/**
 * 语言切换系统 - 统一样式文件
 * 版本: 2.0
 * 功能: 完美适配明暗主题，现代化切换开关设计
 */

/* ============================================
   1. 容器基础样式
   ============================================ */

#language-switcher {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    margin: 0 8px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 100;
    white-space: nowrap;
}

/* ============================================
   2. Light 主题样式（默认）
   ============================================ */

/* Light 背景：渐变紫色背景 + 白色文字 */
body:not([data-theme="dark"]) #language-switcher,
[data-theme="light"] #language-switcher {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

body:not([data-theme="dark"]) #language-switcher:hover,
[data-theme="light"] #language-switcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Light 主题下的按钮样式 */
body:not([data-theme="dark"]) #language-switcher .lang-option,
[data-theme="light"] #language-switcher .lang-option {
    color: rgba(255, 255, 255, 0.7) !important;
    background: transparent;
    border: none;
}

body:not([data-theme="dark"]) #language-switcher .lang-option.active,
[data-theme="light"] #language-switcher .lang-option.active {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.2);
}

body:not([data-theme="dark"]) #language-switcher .lang-option:hover,
[data-theme="light"] #language-switcher .lang-option:hover {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================
   3. Dark 主题样式
   ============================================ */

/* Dark 背景：白色半透明背景 + 深色文字 */
body[data-theme="dark"] #language-switcher,
[data-theme="dark"] #language-switcher {
    background: rgba(255, 255, 255, 0.95) !important;
    color: #2c3e50 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

body[data-theme="dark"] #language-switcher:hover,
[data-theme="dark"] #language-switcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Dark 主题下的按钮样式 */
body[data-theme="dark"] #language-switcher .lang-option,
[data-theme="dark"] #language-switcher .lang-option {
    color: rgba(44, 62, 80, 0.6) !important;
    background: transparent;
    border: none;
}

body[data-theme="dark"] #language-switcher .lang-option.active,
[data-theme="dark"] #language-switcher .lang-option.active {
    color: #2c3e50 !important;
    background: rgba(102, 126, 234, 0.15);
}

body[data-theme="dark"] #language-switcher .lang-option:hover,
[data-theme="dark"] #language-switcher .lang-option:hover {
    color: #2c3e50 !important;
    background: rgba(102, 126, 234, 0.1);
}

/* ============================================
   4. 切换按钮样式
   ============================================ */

.lang-option {
    padding: 2px 8px;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
    font-weight: 500;
    border: none;
    background: transparent;
    outline: none;
    position: relative;
}

.lang-option:active {
    transform: scale(0.95);
}

/* 分隔符 */
.lang-separator {
    color: inherit;
    opacity: 0.3;
    font-weight: 300;
    user-select: none;
}

/* ============================================
   5. 活动状态指示器
   ============================================ */

.lang-option.active::after {
    content: '✓';
    margin-left: 4px;
    font-size: 11px;
    opacity: 0.8;
}

/* ============================================
   6. 响应式设计
   ============================================ */

/* 平板设备 */
@media (max-width: 768px) {
    #language-switcher {
        font-size: 13px;
        padding: 5px 10px;
        gap: 6px;
    }

    .lang-option {
        padding: 3px 10px;
        font-size: 12px;
    }
}

/* 手机设备 */
@media (max-width: 480px) {
    #language-switcher {
        font-size: 12px;
        padding: 4px 8px;
        gap: 4px;
        margin: 0 4px;
    }

    .lang-option {
        padding: 2px 8px;
        font-size: 11px;
    }
}

/* ============================================
   7. 动画效果
   ============================================ */

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

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

#language-switcher {
    animation: fadeIn 0.5s ease-out;
}

/* 切换时的脉冲效果 */
@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.lang-option.switching {
    animation: pulse 0.3s ease;
}

/* ============================================
   8. 无障碍支持
   ============================================ */

#language-switcher:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.lang-option:focus {
    outline: 1px dashed currentColor;
    outline-offset: 2px;
}

/* 高对比度模式 */
@media (prefers-contrast: high) {

    body:not([data-theme="dark"]) #language-switcher,
    [data-theme="light"] #language-switcher {
        background: #5a67d8 !important;
        border: 2px solid #ffffff;
    }

    body[data-theme="dark"] #language-switcher,
    [data-theme="dark"] #language-switcher {
        background: #ffffff !important;
        border: 2px solid #2c3e50;
    }
}

/* 减少动画模式 */
@media (prefers-reduced-motion: reduce) {

    #language-switcher,
    .lang-option {
        transition: none;
        animation: none;
    }
}

/* ============================================
   9. 兼容性修复
   ============================================ */

/* 确保在所有主题中都可见 */
#language-switcher * {
    box-sizing: border-box;
}

/* 防止被其他样式覆盖 */
#language-switcher {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif !important;
    line-height: 1.4 !important;
}

/* ============================================
   10. 打印样式
   ============================================ */

@media print {
    #language-switcher {
        display: none !important;
    }
}

/* ============================================
   11. 加载状态
   ============================================ */

#language-switcher.loading {
    opacity: 0.6;
    pointer-events: none;
}

#language-switcher.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   12. 特殊主题适配
   ============================================ */

/* Butterfly 主题特殊适配 */
#nav .menus_items #language-switcher {
    height: auto;
    line-height: normal;
}

/* 确保在导航栏中垂直居中 */
.menus_items {
    display: flex;
    align-items: center;
}

/* ============================================
   13. 错误状态
   ============================================ */

#language-switcher.error {
    background: rgba(220, 38, 38, 0.9) !important;
    color: #ffffff !important;
}

body[data-theme="dark"] #language-switcher.error {
    background: rgba(220, 38, 38, 0.95) !important;
}

/* ============================================
   14. 工具提示（可选）
   ============================================ */

.lang-option[data-tooltip] {
    position: relative;
}

.lang-option[data-tooltip]:hover::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 11px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    animation: tooltipFadeIn 0.2s ease forwards;
}

@keyframes tooltipFadeIn {
    to {
        opacity: 1;
    }
}