/* ============================================
   📱 SNAPCHAT-STYLE VIDEO CALL - RTL ARABIC
   ============================================ */

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

:root {
    --snap-yellow: #FFFC00;
    --snap-dark: #000000;
    --snap-gray: #8B8B8B;
    --snap-blue: #00C7F2;
    --snap-pink: #FF006E;
    --snap-green: #00FF87;
    --snap-red: #FF3366;
}

body {
    font-family: 'Avenir Next', 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #000000;
    color: #FFFFFF;
    direction: rtl;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

/* ============================================
   JOIN SCREEN - SNAPCHAT STYLE
   ============================================ */
#join-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(180deg, #000000 0%, #1a1a1a 100%);
    padding: 20px;
}

.join-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo {
    margin-bottom: 24px;
}

.ghost-icon {
    font-size: 72px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.join-container h1 {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #FFFFFF;
}

.subtitle {
    font-size: 16px;
    color: var(--snap-gray);
    margin-bottom: 40px;
}

/* Join Now Button */
.join-now-btn {
    width: 100%;
    padding: 20px 32px;
    font-size: 20px;
    font-weight: 700;
    color: var(--snap-dark);
    background: var(--snap-yellow);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 8px 24px rgba(255, 252, 0, 0.3);
}

.join-now-btn:hover {
    background: #FFFF33;
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(255, 252, 0, 0.4);
}

.join-now-btn:active {
    transform: translateY(0);
}

.join-now-btn .icon {
    font-size: 24px;
}

/* Connecting Message */
.connecting-message {
    text-align: center;
    padding: 40px 20px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--snap-yellow);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.connecting-message p {
    font-size: 18px;
    font-weight: 600;
    color: var(--snap-gray);
}

/* Snapchat Login */
.snap-login-container {
    margin-bottom: 24px;
}

.snap-login-btn {
    width: 100%;
    padding: 16px;
    background: #FFFFFF;
    color: var(--snap-dark);
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.2);
}

.snap-login-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 30px rgba(255, 255, 255, 0.3);
}

.snap-login-btn:active {
    transform: scale(0.98);
}

.snap-login-btn .ghost {
    font-size: 24px;
    animation: float 2s ease-in-out infinite;
}

.or-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: var(--snap-gray);
}

.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
}

.or-divider span {
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
}

.input-group {
    margin-bottom: 24px;
}

.input-group input {
    width: 100%;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 30px;
    color: #FFFFFF;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
}

.input-group input:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--snap-yellow);
    transform: scale(1.02);
}

.input-group input::placeholder {
    color: var(--snap-gray);
}

.snap-btn {
    width: 100%;
    padding: 18px;
    background: var(--snap-yellow);
    color: var(--snap-dark);
    border: none;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(255, 252, 0, 0.3);
}

.snap-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(255, 252, 0, 0.5);
}

.snap-btn:active {
    transform: scale(0.98);
}

.snap-btn .icon {
    font-size: 20px;
    font-weight: 700;
}

.error-message {
    margin-top: 16px;
    padding: 12px;
    background: rgba(255, 51, 102, 0.2);
    border-radius: 16px;
    color: var(--snap-red);
    font-size: 14px;
    font-weight: 500;
}

/* ============================================
   CALL SCREEN - FULL IMMERSIVE
   ============================================ */
#call-screen {
    width: 100vw;
    height: 100vh;
    background: var(--snap-dark);
    position: relative;
    overflow: hidden;
}

/* ============================================
   SNAPCHAT TOP BAR (أصلي 100%)
   ============================================ */
.snapchat-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #000000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.snap-icon-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 50%;
}

.snap-icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.9);
}

.snap-call-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: center;
}

.snap-ghost {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.snap-call-text {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.snap-room-name {
    font-size: 15px;
    font-weight: 700;
    color: #FFFFFF;
    letter-spacing: -0.2px;
}

.snap-call-duration {
    font-size: 12px;
    font-weight: 500;
    color: #8B8B8B;
    margin-top: -2px;
}

/* Video Grid - Snapchat Style */
.video-grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 4px;
    padding: 4px;
    padding-top: 60px;
    padding-bottom: 114px;
    background: #000000;
}

/* Dynamic grid layout based on participant count */
.video-grid:has(.video-container:nth-child(1):last-child) {
    grid-template-columns: 1fr;
}

.video-grid:has(.video-container:nth-child(2)) {
    grid-template-columns: 1fr 1fr;
}

.video-grid:has(.video-container:nth-child(3)) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-grid:has(.video-container:nth-child(4)) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-grid:has(.video-container:nth-child(5)) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

.video-container {
    position: relative;
    background: #1a1a1a;
    border-radius: 16px;
    overflow: hidden;
    min-height: 180px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

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

.video-container.local video {
    transform: scaleX(-1);
}

/* ============================================
   SNAPCHAT-STYLE AVATAR
   ============================================ */
.participant-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
    z-index: 5;
}

.avatar-img {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--snap-yellow);
    padding: 10px;
    animation: avatarPulse 2s ease-in-out infinite;
    position: relative;
    z-index: 2;
}

.avatar-ring {
    position: absolute;
    width: 160px;
    height: 160px;
    border: 4px solid var(--snap-yellow);
    border-radius: 50%;
    animation: ringPulse 2s ease-in-out infinite;
    z-index: 1;
}

@keyframes avatarPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes ringPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

.video-container video {
    transition: opacity 0.3s ease;
}

/* ============================================
   SNAPCHAT FLIP CAMERA BUTTON
   ============================================ */
.snap-flip-camera-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.snap-flip-camera-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: var(--snap-yellow);
    transform: scale(1.05);
}

.snap-flip-camera-btn:active {
    transform: scale(0.95);
}

.snap-flip-camera-btn svg {
    animation: rotateIcon 0.3s ease;
}

@keyframes rotateIcon {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(180deg); }
}

/* Hide flip button when camera is off */
.video-container.local .participant-avatar ~ .snap-flip-camera-btn {
    display: none;
}

/* Participant Name Tag */
.participant-info {
    position: absolute;
    bottom: 12px;
    right: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: 20px;
    color: #FFFFFF;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

/* Speaking Indicator */
.video-container.speaking {
    border: 3px solid var(--snap-yellow);
    box-shadow: 0 0 30px rgba(255, 252, 0, 0.6), 0 0 60px rgba(255, 252, 0, 0.3);
    animation: speakingPulse 1s ease-in-out infinite;
}

@keyframes speakingPulse {
    0%, 100% {
        box-shadow: 0 0 30px rgba(255, 252, 0, 0.6), 0 0 60px rgba(255, 252, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 40px rgba(255, 252, 0, 0.8), 0 0 80px rgba(255, 252, 0, 0.5);
    }
}

.video-container.speaking .participant-info {
    background: linear-gradient(135deg, var(--snap-yellow), #FFD700);
    color: var(--snap-dark);
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(255, 252, 0, 0.4);
}

.speaking-icon {
    font-size: 18px;
    animation: speakingBounce 0.6s ease-in-out infinite;
}

@keyframes speakingBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Participant Placeholder (No Video) */
.participant-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.participant-placeholder .avatar {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 12px;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.participant-placeholder .name {
    font-size: 16px;
    font-weight: 700;
    color: #FFFFFF;
}

/* ============================================
   SNAPCHAT BOTTOM CONTROLS (أصلي 100%)
   ============================================ */
.snap-bottom-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 110px;
    background: #000000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 20px;
    z-index: 100;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.snap-side-controls {
    flex: 1;
    display: flex;
    align-items: center;
}

.snap-side-controls:last-child {
    justify-content: flex-end;
}

.snap-control-btn {
    background: transparent;
    border: none;
    color: #FFFFFF;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.snap-control-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.snap-btn-icon {
    font-size: 26px;
}

.snap-btn-label {
    font-size: 11px;
    font-weight: 600;
    color: #FFFFFF;
    opacity: 0.8;
}

.snap-main-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.snap-round-btn {
    width: 68px;
    height: 68px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #FFFFFF;
    font-size: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.snap-round-btn:active {
    transform: scale(0.9);
}

.snap-round-btn.muted {
    background: var(--snap-red);
    border-color: var(--snap-red);
}

.snap-round-btn.snap-primary {
    background: rgba(255, 252, 0, 0.2);
    border-color: var(--snap-yellow);
}

.snap-round-btn.snap-danger {
    background: var(--snap-red);
    border-color: var(--snap-red);
    width: 60px;
    height: 60px;
    font-size: 28px;
}

/* Participants Drawer */
.participants-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 360px;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.participants-drawer:not(.hidden) {
    transform: translateX(0);
}

.drawer-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.drawer-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.btn-close {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #FFFFFF;
    font-size: 20px;
    cursor: pointer;
}

.participants-list {
    padding: 20px;
}

.participant-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
}

.participant-item .avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--snap-yellow), var(--snap-pink));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: var(--snap-dark);
}

.participant-item .name {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
}

/* Status Badge */
.status-badge {
    position: fixed;
    top: 70px;
    right: 20px;
    background: var(--snap-green);
    color: var(--snap-dark);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    z-index: 90;
    animation: fadeIn 0.3s ease;
}

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

.status-badge.connecting {
    background: var(--snap-yellow);
}

.status-badge.disconnected {
    background: var(--snap-red);
    color: #FFFFFF;
}

/* Stats Panel */
.stats-panel {
    position: fixed;
    top: 100px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    padding: 16px;
    border-radius: 16px;
    font-size: 12px;
    min-width: 200px;
    z-index: 90;
}

/* Toast Notification - Snapchat Style */
.toast {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-radius: 30px;
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .video-grid {
        padding: 4px;
        padding-top: 64px;
        padding-bottom: 110px;
        gap: 4px;
    }
    
    .video-container {
        border-radius: 12px;
        min-height: 150px;
    }
    
    .control-btn {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
    
    .control-btn.switch-btn {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    
    .bottom-controls {
        gap: 12px;
        padding: 0 12px;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    .video-grid {
        padding-top: 8px;
        padding-bottom: 80px;
    }
    
    .top-bar {
        height: 50px;
    }
    
    .bottom-controls {
        height: 80px;
        gap: 16px;
    }
    
    .control-btn {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
}

/* ============================================
   TEXT OVERLAY - SNAPCHAT STYLE
   ============================================ */
.text-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.text-input-container {
    width: 100%;
    max-width: 500px;
    position: relative;
}

.close-text-btn {
    position: absolute;
    top: -50px;
    left: 0;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 50%;
    color: #FFFFFF;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-input-container textarea {
    width: 100%;
    min-height: 150px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: #FFFFFF;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    resize: none;
    outline: none;
    font-family: 'Tajawal', sans-serif;
}

.text-input-container textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.send-text-btn {
    width: 100%;
    padding: 16px;
    margin-top: 16px;
    background: var(--snap-yellow);
    color: var(--snap-dark);
    border: none;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-text-btn:active {
    transform: scale(0.95);
}

/* Live Text Messages */
.live-texts {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    z-index: 150;
    pointer-events: none;
}

.live-text-message {
    background: linear-gradient(135deg, rgba(255, 252, 0, 0.95), rgba(255, 106, 0, 0.95));
    backdrop-filter: blur(10px);
    padding: 16px 24px;
    border-radius: 20px;
    margin-bottom: 12px;
    animation: textSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

@keyframes textSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.live-text-message.fade-out {
    animation: textFadeOut 0.4s ease forwards;
}

@keyframes textFadeOut {
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

.text-author {
    font-size: 12px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.7);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.text-content {
    font-size: 20px;
    font-weight: 700;
    color: var(--snap-dark);
    line-height: 1.3;
    word-wrap: break-word;
}

/* Text Button Active State */
.control-btn.text-active {
    background: var(--snap-yellow);
    color: var(--snap-dark);
}

/* Utility Classes */
.text-center { text-align: center; }

/* Smooth Transitions */
button {
    -webkit-tap-highlight-color: transparent;
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}
