:root {
    --bg-color: #f5f5f7;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.4);
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent-color: #0071e3;
    --accent-hover: #0077ed;
    --danger-color: #ff3b30;
    --radius-l: 24px;
    --radius-m: 16px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; outline: none; }

body {
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; }
.container { max-width: 1000px; margin: 0 auto; padding: 20px; width: 100%; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    transition: transform 0.3s ease;
}

.input-group { margin-bottom: 20px; text-align: right; }
.input-group label { display: block; margin-bottom: 8px; font-size: 14px; color: var(--text-secondary); font-weight: 500; }
.input-field {
    width: 100%;
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid #d2d2d7;
    background: rgba(255,255,255,0.8);
    font-size: 16px;
    transition: all 0.2s;
    font-family: inherit;
}
.input-field:focus { border-color: var(--accent-color); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15); }

.btn {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: inline-block;
}
.btn-primary { background: var(--accent-color); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: scale(1.01); }
.btn-secondary { background: #e8e8ed; color: var(--text-primary); margin-top: 10px; }
.btn-secondary:hover { background: #d2d2d7; }
.btn-danger { background: var(--danger-color); color: white; width: auto; padding: 10px 20px; font-size: 14px;}

.toggle-link { text-align: center; margin-top: 20px; font-size: 14px; }
.toggle-link a { color: var(--accent-color); text-decoration: none; font-weight: 500; }
.toggle-link a:hover { text-decoration: underline; }

.room-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; width: 100%; max-width: 1000px; margin-top: 40px; }
.room-card {
    background: white; border-radius: var(--radius-m); padding: 25px; box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.05); cursor: pointer; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex; flex-direction: column; justify-content: space-between; height: 180px;
}
.room-card:hover { transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0,0,0,0.08); border-color: var(--accent-color); }
.room-icon { font-size: 32px; margin-bottom: 15px; color: var(--accent-color); }
.room-name { font-size: 18px; font-weight: 600; margin-bottom: 5px; }
.room-status { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.status-dot { width: 8px; height: 8px; background: #34c759; border-radius: 50%; }

.video-container {
    width: 100%; height: 100vh; display: flex; flex-direction: column; background: #000; position: relative;
}
.video-grid {
    flex:1; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; padding: 15px;
    overflow-y: auto; align-content: center;
}
.video-wrapper {
    position: relative; background: #1c1c1e; border-radius: 16px; overflow: hidden; aspect-ratio: 16/9;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    display: flex; justify-content: center; align-items: center;
}

/* ویدیوها باید همیشه روی هم باشند */
video { 
    position: absolute; 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
    z-index: 1;
}

/* حالت سیاه شدن ویدیو (فقط وقتی کاربر دوربینشو میبنده) */
.video-wrapper.video-off video {
    opacity: 0.1;
    background: #000;
}

/* کانتینر آیکون‌های وضعیت - باید بالاتر از ویدیو باشد */
.peer-status-indicator {
    position: absolute; top: 12px; right: 12px; z-index: 20;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    padding: 4px; border-radius: 8px; display: flex; gap: 4px;
}
.peer-status-icon {
    width: 22px; height: 22px; display: none; fill: white;
}
.peer-status-icon.active { display: block; }
.peer-status-icon.off { fill: #ff3b30; background: rgba(0,0,0,0.5); border-radius: 50%; } /* قرمز */

.user-label {
    position: absolute; bottom: 12px; right: 12px; background: rgba(0,0,0,0.5);
    backdrop-filter: blur(10px); color: white; padding: 4px 12px; border-radius: 8px; font-size: 12px;
    z-index: 10;
}

.controls-bar {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 15px; background: rgba(255,255,255,0.1); backdrop-filter: blur(20px);
    padding: 12px 25px; border-radius: 30px; border: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
}
.control-btn {
    width: 48px; height: 48px; border-radius: 50%; border: none; background: rgba(255,255,255,0.15);
    color: white; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.control-btn:hover { background: rgba(255,255,255,0.25); transform: scale(1.1); }
.control-btn.off { background: var(--danger-color); }
.control-btn svg { width: 22px; height: 22px; fill: currentColor; }

.chat-panel {
    position: absolute; top: 80px; left: 20px; bottom: 100px; width: 320px;
    background: var(--glass-bg); backdrop-filter: blur(25px); border-radius: 20px;
    display: none; flex-direction: column; border: 1px solid var(--glass-border);
    box-shadow: var(--shadow); z-index: 1000;
}
.chat-header { padding: 15px 20px; border-bottom: 1px solid rgba(0,0,0,0.05); font-weight: 600; display: flex; justify-content: space-between; }
.chat-messages { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.message-bubble { padding: 8px 14px; border-radius: 15px; max-width: 85%; font-size: 14px; line-height: 1.4; position: relative; }
.message-bubble.mine { align-self: flex-start; background: var(--accent-color); color: white; border-bottom-right-radius: 4px; }
.message-bubble.others { align-self: flex-end; background: #e8e8ed; color: var(--text-primary); border-bottom-left-radius: 4px; text-align: right; }
.msg-meta { display: block; font-size: 10px; opacity: 0.7; margin-bottom: 2px; }
.chat-input-area { padding: 15px; display: flex; gap: 8px; border-top: 1px solid rgba(0,0,0,0.05); }
.chat-input { flex: 1; padding: 10px 15px; border-radius: 10px; border: 1px solid #d2d2d7; font-size: 14px; }
.chat-send-btn { background: var(--accent-color); color: white; border: none; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; }

.floating-emoji {
    position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%);
    pointer-events: none; animation: floatUp 2s forwards ease-out; z-index: 10;
    display: flex; flex-direction: column; align-items: center;
}
.floating-emoji-char { font-size: 40px; }
.floating-emoji-name { background: rgba(0,0,0,0.6); color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; margin-top: 5px; }
@keyframes floatUp {
    0% { transform: translate(-50%, 0); opacity: 0; }
    20% { opacity: 1; }
    100% { transform: translate(-50%, -150px); opacity: 0; }
}
.emoji-picker {
    position: absolute; bottom: 70px; left: 0; background: white; border-radius: 15px;
    padding: 10px; display: none; grid-template-columns: repeat(5, 1fr); gap: 5px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15); border: 1px solid #eee;
}
.emoji-picker.active { display: grid; }
.emoji-btn { font-size: 20px; padding: 5px; border: none; background: none; cursor: pointer; border-radius: 8px; transition: background 0.2s; }
.emoji-btn:hover { background: #f5f5f7; }

#toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    background: white; padding: 12px 24px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: none; z-index: 9999; font-weight: 500;
}

.connection-pulse {
    width: 8px; height: 8px; border-radius: 50%; background-color: #34c759;
    animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(52, 199, 89, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0); }
}