/* --- 1. 变量定义 --- */
:root {
    --primary-color: #0088cc;        
    --primary-hover: #0056b3;        
    --primary-light: #e6f7ff; 

    /* 浅色模式标准 */
    --bg-color: #f4f6f9;             
    --nav-bg: #ffffff;               
    --card-bg: #ffffff;             
    --text-color: #333333;           
    --text-secondary: #5f6368;       
    --placeholder-color: #999;
    
    --border-color: #dfe1e5;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(32, 33, 36, 0.1);
    
    --glass-blur: 2px;
    --search-height: 50px;
    --btn-radius: 12px;
}

/* 深色模式去蓝化 (Neutral Dark Theme) */
body.dark-mode {
    --primary-color: #63b3ed;
    --primary-hover: #90cdf4;
    --primary-light: rgba(99, 179, 237, 0.1); 

    --bg-color: #121212;             
    --nav-bg: #121212;               
    --card-bg: #1e1e1e;              
    
    --hover-bg: #2d2d2d;
    --text-color: #e0e0e0;           
    --text-secondary: #a0a0a0;       
    --placeholder-color: rgba(255, 255, 255, 0.3);
    
    --border-color: #333333;         
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* --- 2. 基础重置 --- */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0; padding-top: 70px;
    background-color: var(--bg-color); 
    color: var(--text-color);
    line-height: 1.6; 
    
    /* 强制壁纸固定 */
    background-attachment: fixed;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    
    transition: background-color 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased; 
    -webkit-tap-highlight-color: transparent;
    
    min-height: 100vh;
}

input, button { font-family: inherit; }

/* 加载动画 */
.loader-spinner {
    width: 35px; height: 35px; border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto; 
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- 3. 导航栏 --- */
.navbar {
    position: fixed; top: 0; left: 0; width: 100%; height: 70px;
    background-color: var(--nav-bg); box-shadow: var(--shadow-sm);
    border-bottom: 1px solid transparent;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; z-index: 1000; 
    transition: background-color 0.3s, border-color 0.3s, backdrop-filter 0.3s;
}
body.dark-mode .navbar { border-bottom: 1px solid var(--border-color); }

.navbar-brand { font-size: 1.5em; font-weight: 800; color: var(--text-color); text-decoration: none; display: flex; align-items: center; padding-right: 20px; flex-shrink: 0; }
.navbar-brand span { margin-right: 8px; color: var(--primary-color); }

.nav-categories { flex-grow: 1; display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; gap: 4px; margin: 0 10px; scrollbar-width: none; align-items: center; padding: 4px 0; }
.nav-categories::-webkit-scrollbar { display: none; }
.nav-right-side { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.category-icon { width: 16px; height: 16px; margin-right: 6px; flex-shrink: 0; opacity: 0.8; fill: currentColor; }

/* 导航按钮 - 扁平风格 */
.nav-category-link, .nav-dropdown-btn, .btn-login {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 16px; height: 38px;
    background-color: transparent; 
    border: 1px solid transparent; 
    border-radius: var(--btn-radius);
    box-shadow: none;
    color: var(--text-secondary); text-decoration: none; font-weight: 600; font-size: 14px;
    transition: all 0.2s; flex-shrink: 0; line-height: 1.2; cursor: pointer; white-space: nowrap;
}
.nav-category-link:hover, .nav-dropdown-btn:hover, .btn-login:hover { 
    transform: none; box-shadow: none; color: var(--primary-color);
    background-color: rgba(0, 0, 0, 0.05); border-color: transparent;
}
body.dark-mode .nav-category-link:hover, body.dark-mode .nav-dropdown-btn:hover, body.dark-mode .btn-login:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
.nav-category-link.active, .nav-dropdown-btn.active { 
    background-color: var(--primary-light); color: var(--primary-color); 
    border-color: transparent; box-shadow: none; transform: none;
}
.btn-login { color: var(--primary-color); font-weight: 700; }

.nav-dropdown-wrapper { display: inline-flex; align-items: center; flex-shrink: 0; height: 100%; }
.nav-arrow-wrapper { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-left: 6px; margin-right: -8px; border-radius: 50%; transition: background-color 0.2s; }
.nav-arrow { width: 10px; height: 10px; opacity: 0.7; transition: transform 0.2s; fill: currentColor; display: block; margin: 0; }
.nav-dropdown-btn.open .nav-arrow { transform: rotate(180deg); }
.nav-arrow-wrapper:hover { background-color: rgba(0,0,0,0.1); }
body.dark-mode .nav-arrow-wrapper:hover { background-color: rgba(255,255,255,0.15); }

/* PC 悬浮菜单 */
.nav-floating-menu {
    position: fixed; background-color: var(--card-bg); border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.05);
    backdrop-filter: none; -webkit-backdrop-filter: none;
    border-radius: 16px; z-index: 2000; padding: 8px; min-width: 100px; 
    display: none; opacity: 0; transform: translateY(-8px) scale(0.98); 
    transition: opacity 0.2s, transform 0.2s;
}
.nav-floating-menu.show { display: block; opacity: 1; transform: translateY(0) scale(1); }

.nav-menu-item {
    display: flex; align-items: center; padding: 9px 12px; 
    color: var(--text-color); text-decoration: none; font-size: 14px; font-weight: 500;
    border-radius: 10px;
    margin-bottom: 2px; cursor: pointer; transition: all 0.2s; white-space: nowrap; 
}
.nav-menu-item:hover, .nav-menu-item.active { background-color: var(--primary-light); color: var(--primary-color); }
.nav-menu-item svg { margin-right: 10px; opacity: 0.8; width: 16px; height: 16px; transition: opacity 0.2s; }
.nav-menu-item:hover svg, .nav-menu-item.active svg { opacity: 1; fill: currentColor; }

/* --- 4. 搜索框 --- */
.bookmarks-section { max-width: 100%; margin: 0 auto; padding: 0 24px; }
.search-bar-container { padding: 10px 0 15px 0; display: flex; flex-direction: column; align-items: center; animation: fadeInUp 0.8s ease; }
.main-title { font-size: 3.5em; font-weight: 900; color: var(--text-color); margin-bottom: 20px; text-align: center; transition: color 0.3s; }

.search-form {
    position: relative; display: flex; width: 100%; max-width: 680px; height: var(--search-height); 
    background-color: #fafafa; border: 1px solid #e2e8f0; border-radius: 50px; align-items: center; 
    transition: all 0.2s; box-shadow: 0 4px 12px rgba(0,0,0,0.03); 
}
.search-form:hover { background-color: #fff; border-color: #cbd5e0; }
.search-form:focus-within { background-color: #fff; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.15); transform: translateY(-1px); }

.search-input { 
    flex-grow: 1; height: 100%; padding: 0 10px 0 22px; 
    border: none; outline: none; background: transparent; 
    border-radius: 50px 0 0 50px; font-size: 16px; font-weight: 500; 
    color: var(--text-color); caret-color: var(--primary-color); margin: 0; -webkit-appearance: none; 
}
.search-input::placeholder { color: var(--placeholder-color); font-weight: 400; transition: opacity 0.2s; }

.search-button {
    width: 44px; height: 44px; margin-right: 4px; border-radius: 50%; background: transparent; 
    color: var(--primary-color); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; 
    transition: all 0.2s; flex-shrink: 0; opacity: 0.8;
}
.search-button svg { width: 20px; height: 20px; stroke-width: 2.5; }
.search-button:hover { background-color: var(--primary-light); opacity: 1; }

/* 搜索框深色模式去蓝化 */
body.dark-mode .search-form { background-color: #1e1e1e; border-color: #333; }
body.dark-mode .search-form:focus-within { background-color: #1e1e1e; border-color: var(--primary-color); }
body.dark-mode .search-input { color: #fff; }
body.dark-mode .search-button { color: #fff; }
body.dark-mode .search-button:hover { background-color: rgba(255,255,255,0.1); }

/* --- 5. 书签网格 --- */
.bookmark-grid { 
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
    gap: 10px; padding: 15px 0 40px 0; animation: fadeInOnly 0.8s ease 0.1s backwards;
}
.bookmark-card {
    background-color: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--btn-radius); 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
    text-align: center; padding: 8px 4px; text-decoration: none; color: var(--text-color); 
    box-shadow: var(--shadow-sm); transition: box-shadow 0.3s, background-color 0.3s, transform 0.3s; 
    
    height: auto; 
    min-height: 100px; /* PC端卡片高度 100px */
}
.bookmark-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--primary-color); border-color: transparent; }
body.dark-mode .bookmark-card:hover { border-color: var(--primary-color); }
.bookmark-icon { width: 42px; height: 42px; object-fit: contain; margin-bottom: 10px; border-radius: 10px; }
.bookmark-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; padding: 0 2px; line-height: 1.3; }

.bookmark-category-tag {
    font-size: 11px; color: var(--primary-color); background-color: var(--primary-light);
    padding: 2px 8px; border-radius: 10px; margin-top: 6px;
    max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500;
}
body.dark-mode .bookmark-category-tag { background-color: rgba(99, 179, 237, 0.15); color: #63b3ed; }

@keyframes fadeInOnly { from { opacity: 0; } to { opacity: 1; } }

/* --- 6. 壁纸模式 (Glass Mode) --- */
body.has-custom-bg { --glass-text-color: #ffffff; --glass-border: rgba(255, 255, 255, 0.3); --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1); --nav-bg: transparent; }
body.has-custom-bg.is-light-bg { --glass-text-color: #222222; --glass-border: rgba(0, 0, 0, 0.1); }

body.has-custom-bg .main-title,
body.has-custom-bg .navbar-brand,
body.has-custom-bg .nav-category-link,
body.has-custom-bg .nav-dropdown-btn,
body.has-custom-bg .btn-login,
body.has-custom-bg .bookmark-name,
body.has-custom-bg .nav-menu-item,
body.has-custom-bg .mobile-group-header,
body.has-custom-bg .mobile-cat-item {
    color: #ffffff !important;
    text-shadow: none !important;
}

body.has-custom-bg .navbar { background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 100%); backdrop-filter: saturate(120%) blur(2px); border-bottom: 1px solid rgba(255, 255, 255, 0.2); }

/* 导航按钮：壁纸模式下完全透明 */
body.has-custom-bg .nav-category-link,
body.has-custom-bg .nav-dropdown-btn,
body.has-custom-bg .btn-login {
    background: transparent; backdrop-filter: none; border: 1px solid transparent; box-shadow: none;
}
body.has-custom-bg .nav-category-link:hover,
body.has-custom-bg .nav-dropdown-btn:hover,
body.has-custom-bg .btn-login:hover {
    background: rgba(255, 255, 255, 0.2); transform: none; box-shadow: none;
}
body.has-custom-bg .nav-category-link.active,
body.has-custom-bg .nav-dropdown-btn.active {
    background: rgba(255, 255, 255, 0.3); border-color: transparent;
}

/* PC 端壁纸配置 (使用伪元素) */
body.has-custom-bg { background-size: 0 0 !important; background-color: transparent !important; }
body.has-custom-bg::before {
    content: ""; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: -1; 
    background-image: inherit; background-position: center; background-repeat: no-repeat; background-size: cover;
    transform: translateZ(0); will-change: transform; pointer-events: none;
}

/* =========================================================================
   3. 搜索框 & 菜单 核心修正
   ========================================================================= */

/* A. 浅色模式 + 壁纸 */
body.has-custom-bg .search-form { 
    background-color: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.3);
    backdrop-filter: saturate(120%) blur(2px); -webkit-backdrop-filter: saturate(120%) blur(2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
body.has-custom-bg .search-input { color: var(--glass-text-color) !important; caret-color: var(--primary-color); }
body.has-custom-bg .search-button { color: var(--glass-text-color) !important; }
body.has-custom-bg .search-input::placeholder { color: rgba(255, 255, 255, 0.7) !important; }
body.has-custom-bg .search-form:focus-within { 
    background-color: rgba(255, 255, 255, 0.25); border-color: #ffffff; box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.3); 
}

/* B. 深色模式 + 壁纸 */
body.has-custom-bg.dark-mode .search-form { 
    background-color: rgba(0, 0, 0, 0.3); border-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); box-shadow: none;
}
body.has-custom-bg.dark-mode .search-input { color: #ffffff !important; caret-color: #ffffff; } 
body.has-custom-bg.dark-mode .search-button { color: #ffffff !important; }
body.has-custom-bg.dark-mode .search-input::placeholder { color: rgba(255, 255, 255, 0.6) !important; }
body.has-custom-bg.dark-mode .search-form:focus-within { 
    background-color: rgba(0, 0, 0, 0.5); border-color: rgba(255, 255, 255, 0.3); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.1); 
}

/* 悬浮菜单 & 卡片 - 通用玻璃 */
body.has-custom-bg .nav-floating-menu { border: 1px solid var(--glass-border); background: rgba(255, 255, 255, 0.15); backdrop-filter: saturate(120%) blur(2px); }
body.has-custom-bg .nav-floating-menu .nav-menu-item { color: var(--glass-text-color) !important; }
body.has-custom-bg .nav-floating-menu .nav-menu-item:hover { background-color: rgba(255, 255, 255, 0.25); }

body.has-custom-bg .bookmark-card { color: var(--glass-text-color); background: rgba(255, 255, 255, 0.15); backdrop-filter: saturate(120%) blur(2px); border: 1px solid var(--glass-border); }
body.has-custom-bg .bookmark-card:hover { background: rgba(255, 255, 255, 0.25); }
body.has-custom-bg .bookmark-category-tag { background-color: rgba(255, 255, 255, 0.2); color: #fff; }

/* 深色模式 + 壁纸下的悬浮菜单适配（修复背景发白） */
body.has-custom-bg.dark-mode .nav-floating-menu { 
    background: rgba(0, 0, 0, 0.5); /* 纯黑半透 */
    border-color: rgba(255, 255, 255, 0.1);
}
body.has-custom-bg.dark-mode .nav-floating-menu .nav-menu-item:hover { 
    background-color: rgba(255, 255, 255, 0.1); 
}

/* 深色壁纸其他组件 */
body.has-custom-bg.dark-mode .navbar { background: linear-gradient(180deg, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.2) 100%); }
body.has-custom-bg.dark-mode .bookmark-card { background: rgba(0, 0, 0, 0.3); border-color: rgba(255, 255, 255, 0.1); }
body.has-custom-bg.dark-mode .bookmark-card:hover { background: rgba(40, 40, 40, 0.7); }

body.has-custom-bg.dark-mode .nav-category-link,
body.has-custom-bg.dark-mode .nav-dropdown-btn,
body.has-custom-bg.dark-mode .btn-login {
    background: transparent; border-color: transparent;
}
body.has-custom-bg.dark-mode .nav-category-link:hover,
body.has-custom-bg.dark-mode .nav-dropdown-btn:hover,
body.has-custom-bg.dark-mode .btn-login:hover {
    background: rgba(40, 40, 40, 0.7);
}

/* =================================================================
   📱 移动端深度优化
   ================================================================= */
@media (max-width: 768px) {
    /* 1. 启用伪元素作为背景容器 */
    body.has-custom-bg::before {
        content: "";         /* 必须有 content 才能显示 */
        display: block !important;
        position: fixed;     /* 强制固定，不随滚动条移动 */
        top: 0; left: 0; width: 100%; height: 100vh;
        z-index: -1;         /* 置于内容底层 */
        
        /* 继承 Body 的背景图设置，但强制铺满 */
        background-image: inherit; 
        background-position: center center;
        background-repeat: no-repeat;
        background-size: cover;
    }

    /* 2. 隐藏 Body 自身的背景，防止双重显示或滚动冲突 */
    body.has-custom-bg {
        background-size: 0 0 !important;      /* 隐藏 Body 背景图 */
        background-color: transparent !important; /* 确保背景透明 */
        /* 已删除错误的 inherit !important 属性，修复白屏问题 */
    }

    body { padding-top: 60px; }
    .nav-categories { display: none; }
    .navbar { height: 60px; padding: 0 12px; justify-content: flex-start; gap: 12px; }
    .nav-right-side { margin-left: auto; }
    .btn-login { padding: 0 16px; font-size: 13px; height: 32px; border-radius: 10px; }
    .navbar-brand { font-size: 1.2em; padding-right: 0; }
    .main-title { font-size: 2.2em; margin-bottom: 15px; }
    
    .search-input { font-size: 15px; } 
    .search-button { width: 40px; height: 40px; } 
    .search-form { height: 46px; border-radius: 23px; } 

    .bookmark-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .bookmark-card { 
        padding: 6px 4px; 
        min-height: 100px; /* 移动端卡片高度 100px */
    }
    .bookmark-icon { width: 38px; height: 38px; margin-bottom: 8px; }

    .mobile-menu-btn { display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: inherit; padding: 4px; }
    .mobile-menu-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.2); backdrop-filter: blur(5px); z-index: 2001; opacity: 0; visibility: hidden; transition: all 0.3s ease; }
    .mobile-menu-overlay.show { opacity: 1; visibility: visible; }

    .mobile-menu-content {
        position: fixed; top: 60px; left: 12px;
        width: -webkit-fit-content; width: -moz-fit-content; width: fit-content; 
        min-width: 180px; max-width: 80vw;  
        max-height: calc(85vh - 70px);
        background-color: var(--nav-bg); 
        border-radius: 20px; border: 1px solid var(--border-color);
        box-shadow: 0 10px 40px rgba(0,0,0,0.15);
        transform: scale(0.9) translateY(-10px); opacity: 0;
        transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
        z-index: 2002; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 10px;
    }
    .mobile-menu-overlay.show .mobile-menu-content { transform: scale(1) translateY(0); opacity: 1; }

    .mobile-header-text, .mobile-cat-item { display: flex; align-items: center; width: 100%; }
    .mobile-cat-icon { width: 18px !important; height: 18px !important; min-width: 18px; margin-right: 8px; flex-shrink: 0; opacity: 0.7; }
    
    .mobile-group-header { 
        padding: 8px 8px 8px 14px; 
        font-weight: 600; display: flex; justify-content: space-between; align-items: center; 
        font-size: 14px; color: var(--text-color); cursor: pointer; 
        border-radius: 50px; transition: background-color 0.2s;
        white-space: nowrap; margin-right: 4px; 
    }
    
    .mobile-arrow-area { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; margin-left: 4px; cursor: pointer; opacity: 0.6; }
    .mobile-group-container.expanded .mobile-arrow-area svg { transform: rotate(180deg); }

    .mobile-submenu { display: none; flex-direction: column; padding-left: 16px; margin-left: 23px; margin-top: 2px; gap: 4px; border-left: 2px solid var(--border-color); }
    .mobile-group-container.expanded .mobile-submenu { display: flex; }
    
    .mobile-cat-item { 
        padding: 9px 12px; color: var(--text-secondary); font-size: 13.5px; 
        border-radius: 50px; margin-right: 4px; position: relative;
        overflow: hidden; text-overflow: ellipsis;
    }
    .mobile-cat-item::before { content: ''; position: absolute; left: -16px; top: 50%; width: 12px; height: 2px; background-color: var(--border-color); }
    
    .mobile-cat-item.active, .mobile-group-header.active { color: var(--primary-color) !important; background-color: var(--primary-light) !important; font-weight: 600; }

    /* 移动端 + 壁纸 (统一为 2px 微磨砂) */
    body.has-custom-bg .mobile-menu-content { 
        background: rgba(255, 255, 255, 0.15); 
        backdrop-filter: saturate(120%) blur(2px); 
        border: 1px solid rgba(255, 255, 255, 0.3); 
    }
    body.has-custom-bg .mobile-submenu { border-left-color: rgba(255,255,255,0.3); }
    body.has-custom-bg .mobile-group-header, body.has-custom-bg .mobile-cat-item { color: #fff !important; }
    body.has-custom-bg .mobile-cat-item.active, body.has-custom-bg .mobile-group-header.active { background: rgba(255, 255, 255, 0.25) !important; }
    
    body.dark-mode .mobile-menu-content { background: rgba(30, 30, 30, 0.95); }
    /* 深色壁纸模式下的移动端菜单 */
    body.has-custom-bg.dark-mode .mobile-menu-content {
        background: rgba(30, 30, 30, 0.85); 
        border-color: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(2px); 
    }
}

@media (min-width: 769px) { .mobile-menu-btn, .mobile-menu-overlay { display: none !important; } }

/* === 动画效果 === */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
}

.input-error-shake {
    border-color: #e53e3e !important; 
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.2) !important;
    animation: shake 0.4s ease-in-out;
}

.fade-slide-up {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}
.fade-slide-up.show {
    opacity: 1;
    transform: translateY(0);
}