/* 语言选择器样式 */
/* 下拉菜单样式优化 */
.dropdown-style {
  position: relative;
  display: inline-block;
  will-change: transform; /* 优化动画性能 */
}

/* 语言选择器与导航菜单的层级关系优化 */
.language-selector.dropdown-style {
  position: relative;
  z-index: 999; /* 提高层级，确保在头部元素上方可见 */
}

/* 触发按钮样式 */
.selector-trigger {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  min-width: 120px;
  width: auto;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  /* 避免固定为白色，默认继承父元素颜色以保证在浅色/深色头部都可见 */
  color: inherit;
  transition: all 0.2s ease;
}

.selector-trigger .chevron-icon {
  font-size: 10px;
  transition: transform 0.2s ease;
}

.dropdown-style.active .selector-trigger .chevron-icon {
  transform: rotate(180deg);
}

.selector-trigger:hover {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.selector-trigger:active {
  transform: scale(0.98);
}

/* 球形语言logo */
.language-sphere {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

/* 当语言图标 src 为空或加载失败时显示占位色块，防止布局塌陷 */
.language-sphere[alt], .language-sphere {
  background-color: rgba(255,255,255,0.08);
}

/* 加载效果样式 */
.language-loading {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: rgba(44, 62, 80, 0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 6px;
  padding: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 10;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s ease;
  pointer-events: none;
}

/* 加载动画 */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

/* 瀑布流容器 */
.language-options-masonry {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 240px;
  max-width: 320px;
  max-height: 600px;
  padding: 12px;
  background: rgba(44, 62, 80, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.15);
  z-index: 10;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}

/* 瀑布流网格 */
.masonry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  width: 100%;
}

/* 瀑布流项目 */
.masonry-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 4px;
  color: #ffffff;
  text-decoration: none;
  transition: all 0.2s ease;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeInUp 0.3s ease forwards;
  font-size: 13px;
}

/* 保证触发按钮中显示的当前语言可见并在宽度不足时省略号 */
.selector-trigger .current-lang {
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 逐项延迟显示动画 */
.masonry-item:nth-child(1) { animation-delay: 0.05s; }
.masonry-item:nth-child(2) { animation-delay: 0.1s; }
.masonry-item:nth-child(3) { animation-delay: 0.15s; }
.masonry-item:nth-child(4) { animation-delay: 0.2s; }
.masonry-item:nth-child(5) { animation-delay: 0.25s; }
.masonry-item:nth-child(6) { animation-delay: 0.3s; }
.masonry-item:nth-child(7) { animation-delay: 0.35s; }
.masonry-item:nth-child(8) { animation-delay: 0.4s; }
.masonry-item:nth-child(9) { animation-delay: 0.45s; }
.masonry-item:nth-child(10) { animation-delay: 0.5s; }

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.masonry-item img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.masonry-item:hover, .masonry-item:focus {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  outline: none;
}

.masonry-item:active {
  background: rgba(255, 255, 255, 0.25);
}

/* 滚动条优化 */
.language-options-masonry::-webkit-scrollbar {
  width: 5px;
}

.language-options-masonry::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
}

.language-options-masonry::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
}

/* 激活状态 */
.dropdown-style.active .language-options-masonry {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.dropdown-style.active .language-loading {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* 隐藏状态 */
.hidden {
  display: none !important;
}

/* 当前语言高亮 */
.masonry-item.current {
  background: rgba(255, 255, 255, 0.2);
  font-weight: 500;
}

/* 导航栏排版稳定性优化 */
#primary-site-navigation-desktop .main-header-menu > li > a {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 15px;
  min-width: 80px;
  text-align: center;
}

/* 防止长文本破坏导航布局 */
#primary-site-navigation-desktop .main-header-menu {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
}

#primary-site-navigation-desktop .main-header-menu li {
  flex-shrink: 0;
}

/* 移动端语言选择器样式 */
.mobile-language-selector {
  display: none;
}

/* 防止鼠标滚轮滚动导航菜单 */
.main-navigation {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.main-navigation::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

/* 禁止在导航菜单上使用鼠标滚轮 */
.main-navigation {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* 优化长语言名称的显示 */
.masonry-item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .language-options-masonry {
    min-width: 150px;
    max-width: calc(80vw);
    position: absolute; /* 改为绝对定位，相对于按钮定位 */
    top: calc(100% + 5px);
    right: 0; /* 改为右对齐 */
    left: auto; /* 重置左对齐 */
    transform: translateY(8px) scale(0.98);
    margin-top: 0;
    padding: 8px;
  }
  
  /* 移动端语言选择器显示 */
  .mobile-language-selector {
    display: block;
    position: relative;
    margin-left: 15px;
  }
  
  /* 确保移动端语言选择器样式 */
  .mobile-language-selector .selector-trigger {
    min-width: auto;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.15);
  }
  
  .mobile-language-selector .language-sphere {
    width: 20px;
    height: 20px;
  }
  
  .mobile-language-selector .current-lang {
    display: none;
  }
}

/* 针对长语言名称的额外响应式调整 */
@media (max-width: 480px) {
  .language-options-masonry {
    min-width: 120px;
    max-width: calc(80vw);
    transform: translateY(8px) scale(0.98);
  }
  
  .masonry-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  
  .masonry-item {
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .masonry-item img {
    width: 14px;
    height: 14px;
  }
}

/* RTL语言支持 */
.rtl-language #primary-site-navigation-desktop .main-header-menu {
  flex-direction: row-reverse;
}

.rtl-language #primary-site-navigation-desktop .main-header-menu > li > a {
  direction: rtl;
}

/* 确保菜单容器有足够宽度 */
.main-navigation {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 隐藏水平滚动条但保留功能 */
.main-navigation::-webkit-scrollbar {
  height: 0;
}

.main-navigation::-webkit-scrollbar-track {
  background: transparent;
}

.main-navigation::-webkit-scrollbar-thumb {
  background: transparent;
}