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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Home Page Styles */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 3rem;
    color: white;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

header p {
    color: rgba(255,255,255,0.9);
    font-size: 1.1rem;
}

.create-room-section,
.join-room-section {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.create-room-section h2,
.join-room-section h2 {
    margin-bottom: 1.5rem;
    color: #333;
    font-size: 1.5rem;
}

.input-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

input[type="text"] {
    flex: 1;
    padding: 1rem;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    min-width: 200px;
}

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

.btn-primary,
.btn-secondary,
.btn-copy,
.btn-danger {
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #48bb78;
    color: white;
}

.btn-secondary:hover {
    background: #38a169;
    transform: translateY(-2px);
}

.btn-copy {
    background: #ed8936;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
}

.btn-copy:hover {
    background: #dd7724;
}

.btn-danger {
    background: #e53e3e;
    color: white;
}

.btn-danger:hover {
    background: #c53030;
}

.room-created {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    text-align: center;
}

.room-created h3 {
    color: #48bb78;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.invite-info p {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.invite-link-container {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0 2rem 0;
    align-items: center;
}

.share-icons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.share-icon {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.whatsapp-icon {
    background: #25d366;
    color: white;
}

.whatsapp-icon:hover {
    background: #1da851;
    transform: scale(1.1);
}

.telegram-icon {
    background: #0088cc;
    color: white;
}

.telegram-icon:hover {
    background: #006699;
    transform: scale(1.1);
}

.share-button-group {
    display: flex;
    background: #333;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #444;
}

.share-group-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-right: 1px solid #444;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 60px;
}

.share-group-btn:last-child {
    border-right: none;
}

.share-group-btn:hover {
    background: #444;
}

.share-group-btn.active {
    background: #667eea;
}

.share-group-btn.active:hover {
    background: #5a6fd8;
}

.share-group-btn .icon {
    font-size: 1.2rem;
}

.share-group-btn .label {
    font-size: 0.8rem;
}

.invite-link-container input {
    flex: 1;
    padding: 0.75rem;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.hidden {
    display: none;
}

footer {
    text-align: center;
    color: rgba(255,255,255,0.8);
    margin-top: 2rem;
}

/* Room Page Styles */
.room-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    color: white;
}

.room-header {
    background: rgba(0,0,0,0.8);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
}

.room-header h1 {
    font-size: 1.5rem;
}

.room-info {
    display: flex;
    gap: 2rem;
    font-size: 0.9rem;
    color: #ccc;
}

.video-area {
    flex: 1;
    display: flex;
    padding: 1rem;
    gap: 1rem;
    overflow: hidden;
    align-items: center;
}

.local-video-container {
    position: relative;
    width: 300px;
    max-width: 25%;
    background: #333;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16/9;
}

.local-video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.remote-videos-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    height: 100%;
}

.remote-video {
    position: relative;
    background: #333;
    border-radius: 8px;
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 16/9;
    flex: 1;
}

.remote-video video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.remote-video:hover .fullscreen-btn {
    opacity: 1;
}

.fullscreen-btn:hover {
    background: rgba(0,0,0,0.9);
}

.controls {
    background: rgba(0,0,0,0.8);
    padding: 1rem 2rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    border-top: 1px solid #333;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: #333;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 80px;
}

.control-btn:hover {
    background: #444;
}

.control-btn.active {
    background: #667eea;
}

.control-btn.active:hover {
    background: #5a6fd8;
}

.control-btn .icon {
    font-size: 1.2rem;
}

.control-btn .label {
    font-size: 0.8rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    text-align: center;
    min-width: 400px;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: #333;
    margin-bottom: 1.5rem;
}

.modal-content input {
    width: 100%;
    margin-bottom: 1.5rem;
}

.modal-buttons {
    display: flex;
    justify-content: center;
}

/* Device Selection Styles */
.device-selection {
    margin: 1.5rem 0;
    text-align: left;
}

.device-group {
    margin-bottom: 1rem;
}

.device-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.device-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.device-group select:focus {
    outline: none;
    border-color: #667eea;
}

.preview-container {
    margin: 1.5rem 0;
    background: #f7fafc;
    border-radius: 8px;
    padding: 1rem;
}

.preview-container video {
    width: 100%;
    max-height: 150px;
    background: #333;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.preview-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* Device Settings Toggle */
.device-settings-toggle {
    margin: 1rem 0;
}

.btn-toggle {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #f7fafc;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-toggle:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.btn-toggle .arrow {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}

.btn-toggle.expanded .arrow {
    transform: rotate(180deg);
}

.device-settings {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.device-settings.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.device-settings:not(.collapsed) {
    max-height: 600px;
    opacity: 1;
    pointer-events: auto;
}

/* Notifications */
.notifications {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1001;
}

.notification {
    background: #48bb78;
    color: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease;
}

.notification.error {
    background: #e53e3e;
}

.notification.warning {
    background: #ed8936;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Fullscreen Styles */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.fullscreen-overlay.hidden {
    display: none;
}

.exit-fullscreen-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.3s ease;
    z-index: 2001;
}

.exit-fullscreen-btn:hover {
    background: rgba(255,255,255,0.3);
}

.fullscreen-video-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.fullscreen-active {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    aspect-ratio: unset !important;
}

.fullscreen-active video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.fullscreen-active .video-label {
    bottom: 20px;
    left: 20px;
    font-size: 1.2rem;
    padding: 8px 16px;
}

.fullscreen-active .fullscreen-btn {
    display: none;
}

/* Mobile Fullscreen Styles */
.mobile-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: #000 !important;
    object-fit: contain !important;
    border-radius: 0 !important;
}

.mobile-fullscreen-active {
    overflow: hidden;
}

.mobile-fullscreen-active * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Prevent zoom on mobile */
.no-zoom {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Mobile video controls */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-fullscreen {
        object-fit: cover;
    }
    
    .fullscreen-btn {
        font-size: 1.5rem;
        padding: 12px;
        top: 20px;
        right: 20px;
    }
    
    .video-label {
        font-size: 1rem;
        padding: 8px 12px;
        bottom: 20px;
        left: 20px;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .mobile-fullscreen {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Android Chrome specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .mobile-fullscreen {
        position: fixed !important;
        width: 100vw !important;
        height: 100vh !important;
    }
}

/* Connection Quality Indicators */
.connection-indicator {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 10;
    transition: all 0.3s ease;
    cursor: help;
}

.quality-excellent {
    background: rgba(34, 197, 94, 0.9);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.quality-good {
    background: rgba(234, 179, 8, 0.9);
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.5);
}

.quality-fair {
    background: rgba(249, 115, 22, 0.9);
    box-shadow: 0 0 8px rgba(249, 115, 22, 0.5);
}

.quality-poor {
    background: rgba(239, 68, 68, 0.9);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
    animation: pulse-warning 2s infinite;
}

@keyframes pulse-warning {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.1); opacity: 1; }
}

.connection-indicator:hover {
    transform: scale(1.2);
}

/* Enhanced notification styles for connection status */
.notification.connection-info {
    background: #4299e1;
    border-left: 4px solid #2b6cb0;
}

/* 404 Error Modal Styles */
.error-modal {
    text-align: center;
    max-width: 400px;
    padding: 2rem 2.5rem;
}

/* Ensure 404 modal appears above all other overlays */
.modal.room-not-found {
    z-index: 3000;
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.8;
}

.error-modal h2 {
    color: #e74c3c;
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.error-modal p {
    color: #666;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.error-modal .modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.error-modal .btn-secondary {
    background: #6c757d;
    color: white;
}

.error-modal .btn-secondary:hover {
    background: #5a6268;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .room-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .room-info {
        justify-content: center;
    }
    
    .video-area {
        flex-direction: column;
    }
    
    .local-video-container {
        width: 100%;
        height: 200px;
    }
    
    .remote-videos-container {
        grid-template-columns: 1fr;
    }
    
    .controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .control-btn {
        min-width: 60px;
        padding: 0.5rem;
    }
    
    /* Mobile-specific video styles */
    .remote-video video,
    .local-video-container video {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Larger fullscreen button on mobile */
    .fullscreen-btn {
        font-size: 1.2rem;
        padding: 10px;
        opacity: 1; /* Always visible on mobile */
    }
}
