:root{
  --bg:#0b0b0b;
  --panel:#141414;
  --panel2:#1c1c1c;
  --text:#fff;
  --muted:#b7b7b7;
  --brand:#00aeff;
  --danger:#ff4d4f;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: Vazirmatn, Tahoma, sans-serif;
  background:var(--bg);
  color:var(--text);
  overflow:hidden;
}

/* Topbar */
.topbar{
  height:56px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 12px;
  background:rgba(20,20,20,.75);
  backdrop-filter: blur(16px);
  border-bottom:1px solid rgba(255,255,255,.08);
}
.brand{font-weight:700}
.topbar-actions{display:flex; gap:8px}
.icon-btn{
  width:40px;height:40px;border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.04);
  color:var(--text);
  cursor:pointer;
}
.icon-btn:active{transform:scale(.98)}

/* Layout */
.layout{
  height:calc(100% - 56px);
  display:grid;
  grid-template-columns: 260px 1fr;
  gap:10px;
  padding:10px;
}

.sidebar{
  background:rgba(20,20,20,.75);
  backdrop-filter: blur(16px);
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  padding:12px;
  overflow:auto;
}
.sidebar-title{color:var(--muted); margin-bottom:10px}
.room-list{display:flex; flex-direction:column; gap:8px}
.room{
  padding:12px 10px;
  border-radius:12px;
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.06);
  cursor:pointer;
}
.room.active{outline:2px solid rgba(0,174,255,.55)}
.main{min-width:0}

.video-section{
  height:100%;
  background:rgba(20,20,20,.35);
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  overflow:hidden;
  box-shadow:var(--shadow);
}
.video-player-container{
  height:100%;
  width:100%;
  position:relative;
  background:#000;
}
#video{
  width:100%;
  height:100%;
  display:block;
  background:#000;
}
.video-placeholder{
  position:absolute; inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:12px;
  background:linear-gradient(180deg, rgba(0,0,0,.25), rgba(0,0,0,.75));
  color:var(--muted);
  text-align:center;
  padding:20px;
}
.video-placeholder p{margin:0; line-height:1.8}
.video-placeholder:not(.video-placeholder-active){display:none}

/* Floating menus */
.floating-menu{
  position:fixed;
  left:12px;
  bottom:12px;
  width:min(420px, calc(100% - 24px));
  background:rgba(20,20,20,.85);
  backdrop-filter: blur(16px);
  border:1px solid rgba(255,255,255,.10);
  border-radius:18px;
  box-shadow:var(--shadow);
  transform: translateY(130%);
  transition: transform .25s ease;
  overflow:hidden;
  z-index:50;
}
.floating-menu.open{transform: translateY(0)}
.floating-menu-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 12px;
  border-bottom:1px solid rgba(255,255,255,.08);
  color:var(--text);
}
.close-menu-btn{
  width:36px;height:36px;border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.04);
  color:var(--text);
  cursor:pointer;
}
.floating-chat-messages{
  max-height:38vh;
  overflow:auto;
  padding:10px 12px;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.chat-message{font-size:.95rem; line-height:1.6}
.system-message{color:var(--muted); font-style:italic}
.chat-timestamp{color:rgba(255,255,255,.55); font-size:.8rem; margin-left:6px}
.chat-username{color:var(--brand); font-weight:700}

.floating-chat-input{
  display:flex;
  gap:8px;
  padding:10px 12px 12px 12px;
  border-top:1px solid rgba(255,255,255,.08);
}
.floating-chat-input input{
  flex:1;
  border:none;
  border-radius:12px;
  padding:10px 12px;
  background:rgba(255,255,255,.06);
  color:var(--text);
  outline:none;
}
.floating-chat-input button{
  border:none;
  border-radius:12px;
  padding:10px 14px;
  background:var(--brand);
  color:#001018;
  font-weight:700;
  cursor:pointer;
}

.floating-menu-content{padding:12px}
.floating-menu-content p{margin:0 0 10px 0; color:var(--muted); line-height:1.8}
.floating-menu-content input{
  width:100%;
  border:none;
  border-radius:12px;
  padding:10px 12px;
  background:rgba(255,255,255,.06);
  color:var(--text);
  outline:none;
}
.floating-menu-content button{
  width:100%;
  margin-top:10px;
  border:none;
  border-radius:12px;
  padding:10px 14px;
  background:var(--brand);
  color:#001018;
  font-weight:700;
  cursor:pointer;
}
.status-message{margin-top:10px}

/* Username modal */
.username-modal{
  position:fixed; inset:0;
  background:rgba(0,0,0,.65);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:80;
  padding:18px;
}
.username-modal-content{
  width:min(420px, 100%);
  background:rgba(20,20,20,.9);
  border:1px solid rgba(255,255,255,.10);
  border-radius:18px;
  box-shadow:var(--shadow);
  padding:16px;
}
.username-modal-content h3{margin:0 0 12px 0}
.username-modal-content input{
  width:100%;
  border:none;
  border-radius:12px;
  padding:10px 12px;
  background:rgba(255,255,255,.06);
  color:var(--text);
  outline:none;
}
.username-modal-content button{
  width:100%;
  margin-top:10px;
  border:none;
  border-radius:12px;
  padding:10px 14px;
  background:var(--brand);
  color:#001018;
  font-weight:700;
  cursor:pointer;
}

/* Responsive */
@media (max-width: 900px){
  .layout{
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar{
    display:flex;
    gap:8px;
    align-items:center;
    padding:10px;
    overflow:auto;
  }
  .room-list{flex-direction:row; flex-wrap:nowrap}
  .room{white-space:nowrap}
}
@media (max-width: 520px){
  .topbar{padding:0 10px}
  .brand{font-size:.95rem}
  .icon-btn{width:38px;height:38px;border-radius:12px}
  .floating-menu{left:10px; right:10px; width:auto}
}


/* ===== Modern UI additions ===== */
.topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; justify-content:space-between;
  gap:12px;
  padding:10px 14px;
  background: linear-gradient(180deg, rgba(20,20,20,.92), rgba(16,16,16,.84));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.topbar-left,.topbar-right{display:flex; align-items:center; gap:10px;}
.topbar-center{display:flex; align-items:center; gap:12px; flex:1; justify-content:center; min-width:0;}

.brand{display:flex; align-items:center; gap:10px;}
.brand-dot{width:10px; height:10px; border-radius:999px; background: var(--accent); box-shadow:0 0 18px rgba(0,191,255,.45);}
.brand-title{font-weight:800; letter-spacing:.2px}

.room-pill{
  display:flex; align-items:center; gap:8px;
  padding:6px 10px;
  background: rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.08);
  border-radius:999px;
  white-space:nowrap;
}
.room-pill-label{opacity:.7; font-size:12px;}
.room-pill-id{font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono"; font-size:12px;}

.icon-btn{
  width:40px; height:40px;
  display:inline-flex; align-items:center; justify-content:center;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
  color: var(--text);
  cursor:pointer;
}
.icon-btn:hover{background: rgba(255,255,255,.08);}

.primary-btn, .ghost-btn{
  height:40px;
  padding:0 12px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  cursor:pointer;
  display:inline-flex; align-items:center; gap:8px;
  font-weight:700;
}
.primary-btn{
  background: linear-gradient(135deg, rgba(0,191,255,.95), rgba(64,140,255,.9));
  border-color: rgba(0,191,255,.45);
  color:#06121a;
}
.primary-btn:hover{filter: brightness(1.05);}
.ghost-btn{
  background: rgba(255,255,255,.05);
  color: var(--text);
}
.ghost-btn:hover{background: rgba(255,255,255,.08);}

.profile-btn{
  height:40px;
  padding:0 10px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
  display:flex; align-items:center; gap:8px;
  cursor:pointer;
  max-width: 220px;
}
#profile-avatar{
  width:28px; height:28px; border-radius:10px;
  border:1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
}
#profile-name{
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  max-width: 140px;
}

.layout{padding-top:0;} /* topbar is sticky now */

.sidebar{
  transition: transform .18s ease, opacity .18s ease;
}
.sidebar.collapsed{
  transform: translateX(110%);
  opacity: 0;
  pointer-events:none;
}

.sidebar-head{padding:14px 14px 10px;}
.sidebar-title{font-weight:800; font-size:14px;}
.sidebar-sub{opacity:.65; font-size:12px; margin-top:4px;}
.sidebar-footer{padding:12px 14px;}
.hint{
  display:flex; align-items:center; gap:10px;
  padding:10px 12px;
  border-radius:14px;
  background: rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  font-size:12px; opacity:.85;
}

.room-list{padding:0 10px 10px; display:flex; flex-direction:column; gap:10px;}
.room{
  width:100%;
  text-align:right;
  display:flex; justify-content:space-between; align-items:center;
  padding:12px 12px;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
}
.room small{opacity:.6; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono"; font-size:11px;}
.room.active{border-color: rgba(0,191,255,.35); background: rgba(0,191,255,.08);}

.player-shell{
  padding:14px;
}
.video-player-container{
  position:relative;
  width:100%;
  border-radius: 22px;
  overflow:hidden;
  background: #050505;
  border:1px solid rgba(255,255,255,.08);
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
  aspect-ratio: 16 / 9;
}
.video-player-container .active-player{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit: contain;
  background:#000;
}
.video-player-container iframe,
.video-player-container #youtube-player,
.video-player-container #youtube-player iframe{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
}

.video-placeholder{
  position:absolute; inset:0;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:8px;
  background: radial-gradient(1200px 500px at 50% 100%, rgba(0,191,255,.08), transparent 55%),
              radial-gradient(800px 400px at 20% 0%, rgba(255,255,255,.06), transparent 60%),
              rgba(0,0,0,.55);
  color: var(--text);
  text-align:center;
  padding:20px;
}
.ph-icon{
  width:64px; height:64px;
  border-radius:18px;
  display:flex; align-items:center; justify-content:center;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  font-size:26px;
}
.ph-title{font-weight:900; font-size:16px;}
.ph-sub{opacity:.8; font-size:12px; max-width: 520px; line-height:1.7;}

.player-meta{
  margin-top:12px;
  display:flex; align-items:center; justify-content:space-between;
  gap:10px;
  flex-wrap: wrap;
}
.status{
  padding:8px 10px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
  font-size:12px;
  opacity:.9;
}
.meta-actions{display:flex; gap:10px; align-items:center;}

.modal.hidden{display:none;}
.modal{position:fixed; inset:0; z-index:80;}
.modal-backdrop{
  position:absolute; inset:0;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(6px);
}
.modal-card{
  position:relative;
  width:min(520px, calc(100% - 24px));
  margin: 70px auto 0;
  background: rgba(20,20,20,.95);
  border:1px solid rgba(255,255,255,.10);
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.65);
  overflow:hidden;
}
.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.modal-title{font-weight:900;}
.modal-body{padding:14px;}
.field-label{font-size:12px; opacity:.8; margin-bottom:6px;}
.field-input{
  width:100%;
  height:44px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 0 12px;
  outline:none;
}
.field-input:focus{border-color: rgba(0,191,255,.35); box-shadow: 0 0 0 3px rgba(0,191,255,.12);}

.row{display:flex; gap:10px; justify-content:flex-end; margin-top:12px; flex-wrap:wrap;}
.tiny-hint{opacity:.75; font-size:12px; display:flex; gap:8px; align-items:flex-start; line-height:1.6;}
.avatar-grid{
  margin-top:8px;
  display:grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap:10px;
}
.avatar-item{
  width:100%;
  aspect-ratio: 1/1;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
}
.avatar-item.selected{
  border-color: rgba(0,191,255,.45);
  box-shadow: 0 0 0 3px rgba(0,191,255,.10);
}
.avatar-item img{width:100%; height:100%; image-rendering: pixelated;}

@media (max-width: 980px){
  .layout{grid-template-columns: 1fr;}
  .sidebar{position:fixed; right:12px; top:64px; bottom:12px; width:min(320px, calc(100% - 24px)); z-index:60;}
  .main{padding-right:0;}
}
@media (max-width: 520px){
  .topbar-right .primary-btn{display:none;}
  .brand-title{font-size:14px;}
  .avatar-grid{grid-template-columns: repeat(4, minmax(0, 1fr));}
  .modal-card{margin-top: 58px;}
}

/* ===== Theme system (dark/light) ===== */
:root{
  --bg: #0b0b0c;
  --panel: rgba(255,255,255,.05);
  --panel2: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.10);
  --text: #e9eef5;
  --muted: rgba(233,238,245,.72);
  --accent: #00bfff;
  --shadow: rgba(0,0,0,.55);
}
body{
  background: var(--bg);
  color: var(--text);
}
body[data-theme="light"]{
  --bg: #f6f7fb;
  --panel: rgba(0,0,0,.04);
  --panel2: rgba(0,0,0,.03);
  --border: rgba(0,0,0,.10);
  --text: #101217;
  --muted: rgba(16,18,23,.66);
  --accent: #0aa3ff;
  --shadow: rgba(0,0,0,.18);
}
.topbar{
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 86%, transparent), color-mix(in srgb, var(--bg) 72%, transparent));
  border-bottom: 1px solid var(--border);
}
.icon-btn, .profile-btn, .room, .ghost-btn, .status, .hint, .room-pill{
  border-color: var(--border) !important;
  background: var(--panel) !important;
  color: var(--text) !important;
}
.room.active{
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border)) !important;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel)) !important;
}
.player-shell{
  padding: 12px;
}
.video-player-container{
  background: #000;
  border-color: var(--border);
  box-shadow: 0 18px 60px var(--shadow);
}

/* ===== Mobile topbar layout fixes ===== */
@media (max-width: 520px){
  .topbar{
    padding: 8px 10px;
    gap: 8px;
  }
  .topbar-center{
    justify-content:flex-start;
    gap: 8px;
  }
  .brand-title{
    font-size: 13px;
  }
  .room-pill{
    padding: 4px 8px;
  }
  .room-pill-label{display:none;}
  .topbar-right{
    gap: 8px;
  }
  .profile-btn{
    padding: 0 8px;
    border-radius: 12px;
    max-width: 150px;
  }
  #profile-name{max-width: 72px; font-size: 12px;}
  #profile-avatar{width:24px; height:24px; border-radius:9px;}
  .icon-btn{width:36px; height:36px; border-radius:12px;}
  .primary-btn{display:none;} /* create room button hidden on very small screens; still available in menu modal via + button in sidebar? */
  .room-pill-id{font-size:11px;}
}

/* ===== Better layout for very small screens ===== */
@media (max-width: 420px){
  .topbar-left{gap:6px;}
  .topbar-right{gap:6px;}
  .brand-dot{width:8px; height:8px;}
}

/* Make floating menus full-width on mobile */
@media (max-width: 520px){
  .floating-menu{
    width: calc(100% - 24px);
    right: 12px;
    left: 12px;
  }
  .modal-card{
    width: calc(100% - 24px);
    margin-top: 52px;
  }
  .avatar-grid{grid-template-columns: repeat(5, minmax(0, 1fr));}
}
