/* 1. 变量定义层 - 全站色彩总控 */
:root {
    /* 亮色模式 */
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-sub: #666666;
    --sidebar-bg: #ffffff;
    --sub-menu-bg: #fafafa;
    --border-color: rgba(0, 0, 0, 0.05);
    --hover-color: #f0f0f0;
    --input-bg: #ffffff;
    --sidebar-width: 260px;
    --primary-color: #4285f4;
    --header-height: 60px;
    --transition-speed: 0.3s;
				--bg-start-color: #f0f2f5;
				--bg-end-color: #e0e2e5;
    color-scheme: light;
    padding-top: env(safe-area-inset-top);
}

[data-theme="dark"] {
    /* 暗黑模式适配 */
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #e0e0e0;
    --text-sub: #aaaaaa;
    --sidebar-bg: #181818;
    --sub-menu-bg: #222222;
    --border-color: rgba(255, 255, 255, 0.1);
    --hover-color: #2c2c2c;
    --input-bg: #2a2a2a;
				--bg-start-color: #1a1a1a;
				--bg-end-color: #2a2a2a;
    color-scheme: dark;
}
/* 建议放在 [data-theme="dark"] 样式块的附近 */
[data-theme="dark"] img {
    filter: brightness(0.8) contrast(1.2);
    transition: filter 0.4s ease;
}
/* 修改 style.css 中的 #theme-mask */
#theme-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    background: linear-gradient(to bottom right, var(--mask-start), var(--mask-end));
				backdrop-filter: blur(8px); /* 新增：毛玻璃效果 */
				-webkit-backdrop-filter: blur(8px); /* 兼容 Safari */
}

/* 激活状态 */
#theme-mask.active {
    opacity: 1;
}
/* --- 全站滚动条美化 (Chrome, Edge, Safari) --- */
::-webkit-scrollbar {
    width: 8px;  /* 纵向滚动条宽度 */
    height: 8px; /* 横向滚动条高度 */
}

/* 滚动条轨道 */
::-webkit-scrollbar-track {
    background: transparent; 
}

/* 滚动条滑块 (Thumb) */
::-webkit-scrollbar-thumb {
    background: var(--border-color); /* 默认非常淡 */
    border-radius: 10px;
    border: 2px solid transparent; /* 技巧：用透明边框实现滑块与边缘的间隙 */
    background-clip: content-box;
}

/* 鼠标悬停在滚动条上时加深颜色 */
::-webkit-scrollbar-thumb:hover {
    background: var(--text-sub);
    background-clip: content-box;
}

/* --- 针对 Firefox 的兼容性设置 --- */
* {
    scrollbar-width: thin;           /* 变细 */
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent; /* 滑块颜色 轨道颜色 */
}
/* 1. 基础重置与全局设置 */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; overflow-x: hidden; height: 100%; scrollbar-gutter: stable;}
body { 
				font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-color); 
    display: flex; 
    color: var(--text-main);
				transition: background var(--transition-speed), color var(--transition-speed);
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
}

.theme-toggle {
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.theme-toggle:active {
    transform: scale(0.8) rotate(180deg);
}

#theme-icon {
    font-size: 20px;
    display: inline-block;
    transition: all 0.5s;
}
body.no-scroll { overflow: hidden; }

/* 2. 遮罩层 - 只有手机端激活 */
#sidebar-overlay { 
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(0,0,0,0.4); z-index: 998; backdrop-filter: blur(2px);
}
/* 针对桌面安装版 PWA 的特殊处理 */
@media (display-mode: standalone) {
    body {
        /* 确保背景填充整个窗口，不留白边 */
        background-color: var(--bg-color);
        transition: background-color 0.3s ease;
    }
}

/* 3. 侧边栏整体 */
#sidebar { 
    width: var(--sidebar-width); height: 100vh; background: var(--sidebar-bg); 
    border-right: 1px solid var(--border-color); position: fixed; left: 0; top: 0; 
    overflow-y: auto; transition: transform var(--transition-speed) ease, background var(--transition-speed); z-index: 1104;
				/* --- 解决挤压核心代码 --- */
				overflow-y: auto;
				scrollbar-gutter: stable; /* 预留滚动条空间，防止内容跳动 */
}
.logo-container {
    display: flex; flex-direction: row; align-items: center; justify-content: center;
    padding: 30px 10px; gap: 12px; border-bottom: 1px solid var(--border-color); margin-bottom: 10px; background: var(--sidebar-bg);
}

.logo-img { width: 32px; height: 32px; object-fit: contain; }
.logo-text {
    font-size: 18px; /* 稍微缩小一点，更显精致 */
    font-weight: 800; /* 加粗，提升分量感 */
    letter-spacing: 3px; /* 关键：拉开字间距，瞬间有高级感 */
    text-transform: uppercase; /* 强制大写 */
    color: var(--text-main);
    
    /* 渐变文字效果（可选，非常吸睛） */
    background: linear-gradient(135deg, var(--primary-color), #88b1ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    
    /* 加上平滑过渡，切换主题时颜色跟着走 */
    transition: all var(--transition-speed) ease;
    
    /* 消除视觉偏移：稍微向左修正 1.5px 以抵消最后一位字母的字间距 */
    margin-left: 1.5px; 
}
/* 4. 菜单样式 */
.nav-item { padding: 12px 20px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--text-sub); text-decoration: none; }
.nav-item:hover { background-color: var(--hover-color); color: var(--primary-color); }
.folder-header { font-weight: 600; background: var(--sidebar-bg); color: var(--text-main); }
.arrow { font-size: 10px; transition: transform var(--transition-speed); color: #ccc; }
/* 1. 重新定义子菜单容器，使用 Grid 实现平滑高度过渡 */
/* 外层容器：控制 Grid 轨道高度 */
.sub-menu {
    display: grid;
    grid-template-rows: 0fr; /* 默认闭合状态，高度占比为 0 */
    transition: grid-template-rows 0.5s ease-out; /* 针对网格行做动画 */
    overflow: hidden;
}

/* 当父级开启时，轨道高度变为 1 份比例 (即自动撑开) */
.folder-wrapper.open > .sub-menu {
    grid-template-rows: 1fr;
}

/* 内层容器：确保内容有最小高度，动画才不会“跳” */
.sub-menu-inner {
    min-height: 0;
    padding-left: 15px;
    /* 极浅的蓝色背景 */
    background-color: var(--sub-menu-bg); 
    /* 配合主色调的左边框 */
    border-left: 3px solid var(--primary-color); 
    border-radius: 0 8px 8px 0;
}
/* 当分类展开时，文字颜色加深，或者加粗 */
.folder-wrapper.open > .folder-header {
    color: var(--primary-color);
    font-weight: bold;
    background-color: var(--sidebar-bg); /* 保持标题背景纯白，与子菜单的灰色形成对比 */
}
/* 顺便优化一下箭头旋转，让它和卷轴同步 */
.folder-header .arrow {
    transition: transform 0.3s ease;
}
.folder-wrapper.open > .folder-header .arrow {
    transform: rotate(90deg);
}
/* 5. 主内容区 - 布局核心 */
#main-content { 
    margin-left: var(--sidebar-width); 
    flex: 1; 
    padding: 40px; 
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#nav-display { flex: 1; } /* 顶起 Footer */

/* 6. 搜索组件 */
.search-wrapper { display: flex; justify-content: center; margin-bottom: 50px; width: 100%; }
.search-container { 
    display: flex; align-items: center; background: var(--input-bg); 
    border: 2px solid var(--border-color); border-radius: 35px; 
    padding: 8px 18px; width: 100%; max-width: 600px;
}
#current-engine-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    flex-shrink: 0;
}
.search-container:focus-within { border-color: var(--primary-color); box-shadow: 0 8px 25px rgba(66,133,244,0.12); }

/* 顺便优化一下 selector 的间距，让它更精致 */
.engine-selector {
    display: flex;
				position: relative;
				z-index: 1102; /* 确保高于搜索框和遮罩 */
    align-items: center;
    padding-right: 10px;
    margin-right: 5px;
    border-right: 1px solid #eee;
}
.engine-list { 
    position: absolute; top: 45px; left: -10px; background: var(--card-bg); 
    border: 1px solid var(--border-color); color: var(--text-main); border-radius: 12px; list-style: none; 
    display: none; width: 110px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); z-index: 101;
}
.engine-list.show { display: block; animation: fadeIn 0.2s ease; }
.engine-list li { padding: 12px; font-size: 14px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.engine-list li:hover { background: #f8f9fa; border-radius: 10px; }

#search-input { color: var(--text-main); border: none; outline: none; padding: 10px; flex: 1; font-size: 16px; background: transparent; min-width: 0; }
#search-btn { background: none; border: none; color: var(--primary-color); font-weight: bold; cursor: pointer; padding: 0 10px; }

/* 7. 书签卡片 Grid */
.section { margin-bottom: 40px; scroll-margin-top: 20px; width: 100%; }
.section-title { font-size: 16px; margin-bottom: 15px; font-weight: 600; color: var(--text-sub); display: flex; align-items: center; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 15px; width: 100%; }

.card { 
    background: var(--card-bg); padding: 12px; border-radius: 10px; 
    text-decoration: none; color: var(--text-main); display: flex; align-items: center; gap: 12px; 
    border: 1px solid var(--border-color);
				opacity: 0; /* 初始隐藏 */
				animation: fadeInUp 0.5s ease-out forwards; /* 应用动画 */
				/* animation-delay 会在 JS 中动态设置 */
}
/* 瀑布流入场动画的关键帧 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px); /* 从底部稍微向上滑入 */
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.card:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.05); border-color: var(--primary-color); }
.card span {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2; /* 允许显示两行 */
    overflow: hidden;
    font-size: 13px;
    line-height: 1.4;
    white-space: normal; /* 允许换行 */
}

/* 图标容器修复 */
.icon-container { 
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; 
    border-radius: 6px; background: var(--hover-color); flex-shrink: 0; position: relative;
}
.favicon { width: 18px; height: 18px; opacity: 0; transition: opacity 0.3s; z-index: 2; }
.letter-icon { 
    position: absolute; width: 100%; height: 100%; 
    display: none; align-items: center; justify-content: center; /* 修复警告：必须配合 flex */
    font-size: 14px; font-weight: bold; color: #fff; z-index: 1;
}
.icon-container.no-icon .letter-icon { display: flex; } /* 修正为 flex 配合内容居中 */

/* 8. 交互组件 (返回顶部 & 更新提示) */
#back-to-top-pc { 
    position: fixed; bottom: 30px; right: 20px; width: 45px; height: 45px; 
    background: var(--card-bg); border: 1px solid var(--border-color); color: var(--text-main); border-radius: 50%; 
    display: none; align-items: center; justify-content: center; 
    cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 9999; /* 提高层级 */
    transition: all 0.2s;
}
#back-to-top-pc:hover { transform: scale(1.1); background: #f0f0f0; }


/* 9. 响应式布局 */
@media (max-width: 768px) {
    .mobile-header { 
        display: flex; position: fixed; top: 0; left: 0; right: 0;
        height: var(--header-height); background: var(--sidebar-bg); border-bottom: 1px solid var(--border-color);
        align-items: center; justify-content: center; padding: 0 15px; z-index: 1103;
    }
    #menu-toggle {
        position: absolute; left: 15px; background: var(--primary-color); color: white; border: none;
        width: 36px; height: 36px; border-radius: 6px; font-size: 20px;
        display: flex; align-items: center; justify-content: center; cursor: pointer;
    }
    .mobile-logo-box { display: flex; align-items: center; gap: 8px; cursor: pointer; }
    .mobile-logo-box img { height: 26px; }

    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); box-shadow: 10px 0 30px rgba(0,0,0,0.1); }
    #sidebar.open ~ #sidebar-overlay { display: block; }
    
    #main-content { margin-left: 0; padding: calc(var(--header-height) + 20px) 15px 20px; }
    .grid { grid-template-columns: 1fr 1fr !important; gap: 10px; }
    .search-wrapper { margin-bottom: 30px; }
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* --- 更新提示气泡 (Toast) --- */
#update-toast {
    /* 1. 定位与层级 */
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;

    /* 2. 视觉造型：胶囊、深色半透明、毛玻璃 */
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 20px;
    border-radius: 50px;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px); /* 兼容 Safari */
    color: white;
    font-size: 14px;
    
    /* 3. 边框与阴影 */
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);

    /* 4. 入场/退场动画：带点弹性的曲线 */
    transition: all 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
/* 隐藏状态 */
.toast-hidden {
    bottom: -100px !important;
    opacity: 0;
    pointer-events: none; /* 隐藏时不可点 */
}
/* 气泡内的文字 */
#update-toast span {
    letter-spacing: 0.5px;
    font-weight: 500;
}
/* 刷新按钮 */
#update-toast button {
    background: var(--primary-color, #4285f4);
    color: white;
    border: none;
    padding: 5px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: transform 0.2s, background 0.2s;
}
/* 按钮交互效果 */
#update-toast button:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}
#update-toast button:active {
    transform: scale(0.95);
}
/* --- 顶部功能区通用样式 --- */
.top-actions {
    position: absolute; /* 相对于 main-content 定位 */
    z-index: 1001;
}

.theme-toggle {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
}

/* 电脑端定位：放在搜索框右侧水平线上 */
@media (min-width: 769px) {
    .top-actions {
        top: 48px;  /* 调整这个值，让它和搜索框对齐 */
        right: 40px; /* 距离右边距 */
    }
}

/* 手机端定位：放在顶部白条右侧 (对应 image_0e1245.png) */
@media (max-width: 768px) {
    .top-actions {
        position: fixed; /* 手机端需要固定在顶部条上 */
        top: 10px;      /* 对应顶部白条的高度中间 */
        right: 15px;    /* 靠右显示 */
        z-index: 10001;  /* 确保在所有元素最上方 */
    }
    
    .theme-toggle {
    background: var(--primary-color); /* 统一使用主色调背景 */
    color: white; /* 图标颜色 */
    border: none;
    width: 36px; /* 统一尺寸 */
    height: 36px;
    border-radius: 6px; /* 统一圆角，和 #menu-toggle 一致 */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    box-shadow: none; /* 去掉多余阴影 */
    }
}