body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #c8e3de;
    color: #e0e0e0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 1rem;
    box-sizing: border-box;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 95vw;
    max-width: 1500px;
    height: 95vh;
    background-color: #1e1e1e;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* Main Content: Video and Controls */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
}

.header-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
    margin-bottom: 1.5rem;
    width: 100%;
}

.header-logo {
    position: absolute;
    left: 0;
    height: 65px;
    width: auto;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.main-header {
    text-align: center;
    color: #c8e3de;
    margin: 0;
    font-size: 2rem;
}

.video-area {
    position: relative;
    width: 100%;
    flex-grow: 1;
    min-height: 0;
    background-color: #000;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#remoteVideo {
    width: 100%;
    height: 100%;
    object-fit: con;
}

.video-grid {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    align-content: center;
    gap: 8px;
    padding: 8px;
    box-sizing: border-box;
    z-index: 5;
}

.remote-video-wrapper {
    position: relative;
    background: #222;
    border: 3px solid transparent;
    box-sizing: border-box;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.remote-video-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #000;
}

/* dynamic grid sizes */
.video-grid.count-1 .remote-video-wrapper {
    width: 100%;
    height: 100%;
    max-width: 100%;
}

.video-grid.count-2 .remote-video-wrapper {
    width: 48%;
    height: 100%;
}

.video-grid.count-3-plus .remote-video-wrapper {
    width: 48%;
    height: 48%;
}

.user-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remote-video-wrapper.speaking .user-label,
.local-video-wrapper.speaking .user-label {
    background: rgba(33, 150, 243, 0.95);
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.6);
    border-color: #2196f3;
}

.remote-video-wrapper.playing-audio .user-label,
.local-video-wrapper.playing-audio .user-label {
    background: rgba(255, 152, 0, 0.95);
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.6);
    border-color: #ff9800;
}

.speaking {
    border: 3px solid #2196f3 !important;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.6);
    transition: all 0.2s ease-in-out;
}

.playing-audio {
    border: 3px solid #ff9800 !important;
    box-shadow: 0 0 15px rgba(255, 152, 0, 0.6);
    transition: all 0.2s ease-in-out;
}

.video-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
    color: #e0e0e0;
    font-size: 1.2rem;
    font-weight: 500;
    z-index: 10;
}

.local-video-wrapper {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    width: 220px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    z-index: 20;
    background: #000;
    transition: all 0.2s ease-in-out;
}

.local-video-wrapper video {
    width: 100%;
    height: auto;
    display: block;
}

.controls-area {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
    flex-shrink: 0;
}

.speaker-setup {
    display: flex;
    gap: 1.5rem;
    flex-grow: 1;
}

.speaker-setup > div {
    flex-basis: 200px;
    flex-grow: 1;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #a0a0a0;
}

select {
    width: 100%;
    padding: 0.6rem;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #2c2c2c;
    color: #e0e0e0;
    font-size: 1rem;
}

button {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s;
}

.session-buttons {
    display: flex;
    gap: 1rem;
}

.media-toggle {
    background-color: #1db954;
}

.media-toggle:hover {
    background-color: #1aa34a;
}

.media-toggle.muted {
    background-color: #cf6679;
}

.media-toggle:disabled {
    background-color: #444;
    color: #777;
    cursor: not-allowed;
}

#connectButton { background-color: #1db954; color: #ffffff; font-weight: bold; }
#connectButton:hover { background-color: #1aa34a; }
#connectButton:disabled { background-color: #444; color: #777; cursor: not-allowed;}

#disconnectButton { background-color: #d32f2f; }
#disconnectButton:hover { background-color: #b71c1c; }
#disconnectButton:disabled { background-color: #444; color: #777; cursor: not-allowed; }

/* --- Meeting Workspace & Sidebar --- */
.meeting-workspace {
    display: flex;
    flex-direction: row;
    flex-grow: 1;
    min-height: 0;
    gap: 1rem;
    width: 100%;
    overflow: hidden;
}

.caption-sidebar {
    width: 320px;
    background-color: #161616;
    border: 1px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: all 0.3s ease;
    overflow: hidden;
}

.caption-sidebar.hidden {
    display: none !important;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #2a2a2a;
    background-color: #1f1f1f;
}

.caption-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    font-weight: 700;
}

.sidebar-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.2s;
}

.sidebar-close:hover {
    color: #fff;
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Custom Scrollbar */
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}
.sidebar-content::-webkit-scrollbar-track {
    background: #121212;
}
.sidebar-content::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}
.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* --- Chat Bubbles --- */
.caption-bubble {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.92rem;
    line-height: 1.4;
    word-break: break-word;
    animation: fadeIn 0.25s ease-out;
}

.bubble-name {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 4px;
    opacity: 0.85;
}

.caption-bubble.self {
    align-self: flex-end;
    background-color: #0d5c46;
    color: #e2f0d9;
    border-bottom-right-radius: 2px;
    border: 1px solid #147a5e;
}

.caption-bubble.others {
    align-self: flex-start;
    background-color: #2a2a2a;
    color: #e0e0e0;
    border-bottom-left-radius: 2px;
    border: 1px solid #3d3d3d;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.speaking {
    outline: 3px solid #2196f3 !important;
    outline-offset: -3px;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.8) !important;
    border-color: transparent !important;
    transition: all 0.2s ease-in-out;
}

.playing-audio {
    outline: 3px solid #ff9800 !important;
    outline-offset: -3px;
    box-shadow: 0 0 15px rgba(255, 152, 0, 0.8) !important;
    border-color: transparent !important;
    transition: all 0.2s ease-in-out;
}

/* Pre-Join Lobby design */
.lobby-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(20, 20, 20, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 2rem 1rem;
    box-sizing: border-box;
}

.lobby-box {
    background: #1e1e1e;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    border: 1px solid #333;
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    margin: auto;
}

.lobby-content {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.lobby-left, .lobby-right {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.lobby-translation-setup {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.lobby-translation-setup .device-group {
    flex: 1;
}

#lobbyVideo {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid #333;
}

.device-group label {
    font-size: 0.9rem;
    color: #c8e3de;
    display: block;
    margin-bottom: 0.3rem;
}

.device-group input, .device-group select {
    width: 100%;
    padding: 0.6rem;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #2c2c2c;
    color: white;
    box-sizing: border-box;
}

.mic-meter {
    height: 6px;
    background: #444;
    border-radius: 3px;
    margin-top: 8px;
    overflow: hidden;
}

.mic-fill {
    height: 100%;
    background: #00e676;
    width: 0%;
    transition: width 0.1s ease;
}

.join-btn {
    background: #64cc74;
    font-size: 1.1rem;
    font-weight: bold;
    padding: 1rem;
    border: none;
    border-radius: 6px;
    color: #121212;
    cursor: pointer;
    transition: background-color 0.2s;
}
.join-btn hover {background: #52b862;}

.session-info {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-grow: 1;
    flex-wrap: wrap;
}
.info-badge {
    background: #2c2c2c;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    color: #aaa;
    border: 1px solid #444;
}
.info-badge strong {
    color: #fff;
    margin-left: 5px;
}

/* --- Responsive Design for Mobile --- */
@media (max-width: 800px) {
    body {
        padding: 0;
    }
    .app-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }

    .main-content {
        padding: 0.8rem;
    }

    .header-container {
        margin-bottom: 0.8rem;
        justify-content: flex-start;
        padding-left: 45px;
        min-height: 40px;
    }
    .header-logo {
        height: 30px;
    }
    .main-header {
        font-size: 1.3rem;
        text-align: left;
    }

    /* video frame & layout controls */
    .video-area {
        border-radius: 6px;
    }
    .local-video-wrapper {
        width: 120px; /* Smaller PIP on mobile */
        bottom: 8px;
        right: 8px;
    }

    /* dynamic video grid */
    .video-grid {
        gap: 6px;
        padding: 6px;
    }
    .video-grid.count-2 .remote-video-wrapper {
        width: 100%;
        height: 49%;
    }
    .video-grid.count-3-plus .remote-video-wrapper {
        width: 100%;
        height: 32%;
    }
    .user-label {
        bottom: 6px;
        left: 6px;
        font-size: 0.75rem;
        padding: 2px 6px;
    }

    .meeting-workspace {
        flex-direction: column;
    }
    .caption-sidebar {
        width: 100%;
        height: 220px;
        flex-shrink: 0;
    }

    .controls-area {
        margin-top: 0.8rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.8rem;
    }

    .session-info {
        display: flex;
        justify-content: space-between;
        gap: 0.4rem;
        width: 100%;
    }

    .info-badge {
        flex: 1;
        text-align: center;
        padding: 0.4rem 0.2rem;
        font-size: 0.75rem;
        border-radius: 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .info-badge strong {
        margin-left: 2px;
    }

    .session-buttons {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.4rem;
    }

    .session-buttons button {
        width: 100%;
        padding: 0.8rem 0.2rem;
        font-size: 0.8rem;
        font-weight: 600;
        text-align: center;
        border-radius: 6px;
        white-space: nowrap;
    }

    .remote-video-wrapper {
        min-height: 30%;
    }

    
    /* joining lobby */
    .lobby-overlay {
        padding: 1rem 0.5rem;
    }
    .lobby-box {
        padding: 1.5rem;
    }
    .lobby-content {
        gap: 1.5rem;
    }

    .lobby-left, .lobby-right {
        min-width: 100%;
    }

    .lobby-translation-setup {
        flex-direction: column;
        gap: 1rem;
    }

    .device-group input, .device-group select {
        font-size: 16px;
    }
}

/* for Ultra-Small screens */
@media (max-width: 380px) {
    .main-header {
        display: none;
    }
    .header-container {
        padding-left: 0;
        justify-content: center;
    }
    .session-buttons button {
        font-size: 0.7rem;
    }
}