* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

#app {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.dark-mode .screen {
    background: #2d2d2d;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid #404040;
}

.hidden {
    display: none !important;
}

h1 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 2.5rem;
}

.dark-mode h1 {
    color: #64b5f6;
}

h2 {
    color: #34495e;
    margin-bottom: 1rem;
}

.dark-mode h2 {
    color: #90caf9;
}

p {
    margin-bottom: 1.5rem;
    color: #7f8c8d;
}

.dark-mode p {
    color: #b0b0b0;
}

#name-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

input[type="text"] {
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s;
    background-color: white;
    color: #333;
}

.dark-mode input[type="text"] {
    border: 2px solid #505050;
    background-color: #404040;
    color: #e0e0e0;
}

input[type="text"]:focus {
    outline: none;
    border-color: #3498db;
}

.dark-mode input[type="text"]:focus {
    border-color: #64b5f6;
}

button {
    padding: 0.75rem 2rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

.dark-mode button {
    background-color: #1976d2;
}

button:hover {
    background-color: #2980b9;
}

.dark-mode button:hover {
    background-color: #1565c0;
}

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

.dark-mode button:disabled {
    background-color: #666666;
}

.loader {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

.dark-mode .loader {
    border: 5px solid #404040;
    border-top: 5px solid #64b5f6;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.waiting-video {
    width: 200px;
    height: 150px;
    border-radius: 8px;
    border: 2px solid #3498db;
    margin-top: 1rem;
    background: #000;
    object-fit: cover;
}

.dark-mode .waiting-video {
    border-color: #64b5f6;
}

#video-screen {
    max-width: fit-content;
    width: auto;
    height: auto;
    max-height: 95vh;
    position: relative;
    padding: 1rem;
    border-radius: 12px;
    background: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.dark-mode #video-screen {
    background: #2d2d2d;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid #404040;
}

.video-container {
    display: grid;
    grid-template-columns: auto auto;
    gap: 1rem;
    width: auto;
    margin: 0;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
}

.video-container.single-video {
    grid-template-columns: 1fr;
    justify-items: center;
}

.video-container.single-video video {
    width: auto;
    height: auto;
    max-width: 85vw;
    max-height: calc(90vh - 8rem);
}

.video-container:has(#local-video.hidden) {
    grid-template-columns: 1fr;
    justify-items: center;
}

/* Ensure remote video is always positioned first in grid */
#remote-video {
    grid-column: 1;
}

#local-video:not(.hidden) {
    grid-column: 2;
}

video {
    width: auto;
    height: auto;
    max-width: 45vw;
    max-height: calc(90vh - 8rem);
    background-color: #000;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.dark-mode video {
    background-color: #000;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.connection-status {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    font-size: 0.875rem;
    color: white;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s ease;
    z-index: 100;
}

.connection-status.hidden-status {
    display: none;
}

.dark-mode .connection-status {
    background-color: rgba(255, 255, 255, 0.1);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #95a5a6;
    animation: pulse 2s infinite;
}

.status-dot.connecting {
    background-color: #f39c12;
}

.status-dot.connected {
    background-color: #27ae60;
    animation: none;
}

.status-dot.disconnected {
    background-color: #e74c3c;
}

.status-dot.reconnecting {
    background-color: #f39c12;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.status-text {
    color: white;
    font-weight: 500;
}

.dark-mode .status-text {
    color: white;
}



/* Common styles for icon buttons */
.theme-toggle,
.fullscreen-toggle,
.self-view-toggle.top-bar-toggle {
    position: fixed;
    top: 1rem;
    width: 45px;
    height: 45px;
    border-radius: 8px;
    background: #3498db;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

/* Blue buttons on top left - consistent spacing for all screen sizes */
.theme-toggle {
    left: 1rem;
}

.fullscreen-toggle {
    left: 5.75rem;
}

.self-view-toggle.top-bar-toggle {
    left: 10.5rem;
}

/* Exit button on top right */
.exit-btn.top-bar-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    height: 45px;
    padding: 0 1rem;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover,
.fullscreen-toggle:hover,
.self-view-toggle.top-bar-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.exit-btn.top-bar-toggle:hover {
    background: #c0392b;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dark-mode .theme-toggle,
.dark-mode .fullscreen-toggle,
.dark-mode .self-view-toggle.top-bar-toggle {
    background: #1976d2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dark-mode .exit-btn.top-bar-toggle {
    background: #d32f2f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.dark-mode .theme-toggle:hover,
.dark-mode .fullscreen-toggle:hover,
.dark-mode .self-view-toggle.top-bar-toggle:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.dark-mode .exit-btn.top-bar-toggle:hover {
    background: #b71c1c;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 768px) {
    #video-screen {
        max-width: 95vw;
        width: auto;
        padding: 0.5rem;
    }
    
    .video-container {
        grid-template-columns: 1fr;
        margin: 0;
        gap: 0.5rem;
    }
    
    video {
        width: auto;
        height: auto;
        max-width: 90vw;
        max-height: 45vh;
    }
    
    .video-container.single-video video {
        width: auto;
        height: auto;
        max-width: 95vw;
        max-height: 80vh;
    }
    
    /* On mobile, stack videos vertically with remote first */
    #remote-video {
        grid-column: 1;
        grid-row: 1;
    }
    
    #local-video:not(.hidden) {
        grid-column: 1;
        grid-row: 2;
    }
    
    .theme-toggle,
    .fullscreen-toggle,
    .self-view-toggle.top-bar-toggle {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        top: 0.5rem;
    }
    
    .exit-btn.top-bar-toggle {
        top: 0.5rem;
        height: 40px;
        padding: 0 0.8rem;
        font-size: 0.8rem;
    }
}