/* ========================================
 * 工具分享平台 - 前台样式
 * 布局：左侧固定侧边栏 + 右侧内容区
 * 配色：简约清新(#f7f8fa) + 彩色模式(黄金角度自动配色)
 * 响应式断点：1200 / 1024 / 768 / 480 / 380
 * ======================================== */

/* ========== 全局重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    color-scheme: light;
    letter-spacing: 0.05em;
}

body {
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f7f8fa;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ========== 背景纹理 ========== */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background-image: image-set(
        url('../images/tool-background.webp') type('image/webp'),
        url('../images/tool-background.jpg') type('image/jpeg')
    );
    background-size: cover;
    background-position: center;
    opacity: 0.9; /* 彩色模式通过 body.colorful::before 覆盖为 1 */
}

/* ========== 侧边栏 ========== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 220px;
    background: #fff;
    border-right: 1px solid rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}
.sidebar-brand a { display: flex; align-items: center; gap: 10px; }
.sidebar-brand img { border-radius: 8px; }
.sidebar-brand span { font-size: 17px; font-weight: 700; color: #1a1a1a; }

.sidebar-nav { flex: 1; padding: 16px 10px; overflow-y: auto; }

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    transition: all .15s;
    margin-bottom: 2px;
}
.sidebar-item:hover { background: rgba(0,0,0,0.03); color: #333; }
.sidebar-item.active { background: #f0f0f0; color: #1a1a1a; font-weight: 500; }
.sidebar-item .sidebar-icon { flex-shrink: 0; opacity: 0.6; }
.sidebar-item.active .sidebar-icon,
.sidebar-item:hover .sidebar-icon { opacity: 1; }

.sidebar-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sidebar-count { display: none; } /* 已隐藏 */

/* 侧边栏底部（登录 + 主题/语言切换） */
.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.sidebar-footer-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.sidebar-footer .sidebar-item { margin: 0; }

/* ========== 通用切换按钮（主题/语言共用） ========== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 6px 8px;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}
.theme-toggle:hover { border-color: rgba(0,0,0,0.15); }
.theme-toggle.active { border-color: rgba(0,0,0,0.15); box-shadow: 0 0 0 2px rgba(100,100,100,0.15); }

.theme-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    transition: filter .2s;
}
.theme-toggle.active .theme-swatch { filter: saturate(1.3); }

.lang-toggle {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 4px 8px;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
    font-size: 12px;
    font-weight: 600;
    color: #bbb;
    user-select: none;
    line-height: 1;
}
.lang-toggle:hover { border-color: rgba(0,0,0,0.15); }
.lang-toggle .lang-sep { color: #ccc; margin: 0; }
.lang-toggle .lang-active { color: #5b8def; }

/* ========== 移动端顶部栏 ========== */
.mobile-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 150;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    padding: 10px 16px;
    align-items: center;
    justify-content: space-between;
}
.mobile-header-actions { display: flex; align-items: center; gap: 10px; }
.mobile-header .lang-toggle { border-radius: 4px; padding: 3px 6px; font-size: 11px; }

.mobile-theme-toggle {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: none;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 4px;
    cursor: pointer;
}
.mobile-theme-toggle .theme-swatch { width: 10px; height: 10px; border-radius: 2px; display: block; }

.menu-toggle { background: none; border: none; color: #555; cursor: pointer; padding: 4px; display: flex; align-items: center; }

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
}
.mobile-brand img { border-radius: 6px; }

/* ========== 主内容区 ========== */
.main-content {
    margin-left: 220px;
    padding: 36px 40px 60px;
    min-height: 100vh;
}

/* ========== 搜索区域 ========== */
.search-center { max-width: 960px; margin: 0 auto; }
.search-section { text-align: center; padding: 48px 0 36px; }
.search-header { margin-bottom: 26px; }
.search-header h1 { font-size: 28px; font-weight: 700; color: #1a1a1a; margin-bottom: 6px; }
.search-header p { color: #999; font-size: 15px; }
.search-header-row { display: flex; align-items: center; gap: 12px; justify-content: center; }

.search-container { max-width: 680px; margin: 0 auto; }
.search-box { position: relative; width: 100%; margin: 0 auto 14px; }

.search-input-wrapper {
    display: flex;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color .2s, box-shadow .2s;
}
.search-input-wrapper:focus-within { border-color: #c0c0c0; box-shadow: 0 0 0 3px rgba(0,0,0,0.04); }

.search-txt { flex: 1; padding: 12px 16px; border: none; font-size: 15px; outline: none; background: transparent; }
.search-btn { background: transparent; color: #999; border: none; padding: 12px 18px; cursor: pointer; transition: color .2s; }
.search-btn:hover { color: #555; }

/* 站外搜索引擎 */
.search-engines { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.search-engine-btn {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid #e8e8e8;
    border-radius: 20px;
    color: #888;
    font-size: 13px;
    transition: all .2s;
}
.search-engine-btn:hover { border-color: #c0c0c0; color: #555; background: #fff; }

/* ========== 工具卡片 ========== */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.tool-card {
    background: linear-gradient(160deg, #ffffff 0%, #fafbfc 60%, #f5f6f8 100%);
    border: 1px solid rgba(0,0,0,0.04);
    border-radius: 14px;
    padding: 20px 22px;
    text-align: left;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 8px rgba(0,0,0,0.03), 0 0 0 0.5px rgba(0,0,0,0.02);
    transition: transform .2s, box-shadow .2s, border-color .2s;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}
.tool-card:hover {
    border-color: rgba(0,0,0,0.06);
    transform: translateY(-3px);
    background: linear-gradient(160deg, #ffffff 0%, #fcfcfd 60%, #f7f8fa 100%);
    box-shadow: 0 2px 4px rgba(0,0,0,0.04), 0 8px 20px rgba(0,0,0,0.07), 0 0 0 0.5px rgba(0,0,0,0.03);
}

.tool-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 6px;
    line-height: 1.4;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}
.tool-card p {
    color: #888;
    font-size: 12px;
    margin-top: auto;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 卡片标签（紧贴工具名右侧，使用 firstChild.textContent 翻译时不被清除） */
.card-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 500;
    padding: 0 5px;
    border-radius: 3px;
    background: rgba(0,0,0,0.06);
    color: #999;
    line-height: 1.7;
    vertical-align: middle;
    margin-left: 4px;
    flex-shrink: 0;
    pointer-events: none;
    white-space: nowrap;
}

/* ========== 分类分组 ========== */
.category-group { scroll-margin-top: 60px; margin-bottom: 29px; }
.category-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; margin-top: -2px; padding: 8px 12px; border-radius: 10px; }
.category-indicator { width: 3px; height: 18px; background: #c5c5c5; border-radius: 2px; }
.category-name { font-size: 14px; font-weight: 600; color: #666; }

/* ========== 区域标题 ========== */
.section-header { margin-bottom: 14px; }
.section-title { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; color: #666; margin: 0; }
.section-desc { color: #999; font-size: 13px; margin-top: 6px; }
.hot-tools { scroll-margin-top: 60px; margin-bottom: 36px; }
.results-section { margin: 24px 0; }

/* ========== 页脚 ========== */
.footer {
    border-top: 1px solid rgba(0,0,0,0.05);
    margin-top: 48px;
    margin-left: 220px;
    padding: 0 40px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.footer-content {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}
.footer-content p { color: #bbb; font-size: 12px; }
.footer-links { display: flex; gap: 20px; }
.footer-links a { color: #bbb; font-size: 12px; transition: color .2s; }
.footer-links a:hover { color: #888; }

/* ========== 彩色卡片模式 ========== 
 * CSS 自定义属性 --cat-hue 驱动配色
 * PHP 端按黄金角度(137.5°)自动分配色相 */

body.colorful { background-color: #fdfcf9; }
body.colorful::before { opacity: 1; }
body.colorful .sidebar { background: rgba(255,255,255,0.45); border-right-color: rgba(0,0,0,0.06); }
body.colorful .main-content { background: transparent; }
body.colorful .mobile-header { background: rgba(255,255,255,0.15); }
body.colorful .footer { border-top-color: rgba(180,160,120,0.15); }
body.colorful .footer-content p,
body.colorful .footer-links a { color: #888; }

/* 彩色：卡片 */
body.colorful .tool-card {
    border: none;
    background: hsl(var(--cat-hue, 210), 38%, 72%);
    color: hsl(var(--cat-hue, 210), 22%, 28%);
}
body.colorful .tool-card:hover {
    background: hsl(var(--cat-hue, 210), 42%, 66%);
    box-shadow: 0 2px 4px hsl(var(--cat-hue, 210), 30%, 40%, .12), 0 8px 20px hsl(var(--cat-hue, 210), 30%, 40%, .16);
}
body.colorful .tool-card h3 { color: hsl(var(--cat-hue, 210), 28%, 22%); }
body.colorful .tool-card p  { color: hsl(var(--cat-hue, 210), 16%, 40%); }
body.colorful .card-badge { background: rgba(255,255,255,0.45); color: hsl(var(--cat-hue, 210), 20%, 32%); }

/* 彩色：侧边栏分类项 */
body.colorful .sidebar-item[style] { color: hsl(var(--cat-hue, 210), 22%, 32%); font-weight: 600; }
body.colorful .sidebar-item[style]:hover { background: hsl(var(--cat-hue, 210), 30%, 82%); color: hsl(var(--cat-hue, 210), 20%, 24%); }
body.colorful .sidebar-item[style].active { background: hsl(var(--cat-hue, 210), 38%, 78%); color: hsl(var(--cat-hue, 210), 22%, 22%); font-weight: 500; }
body.colorful .sidebar-item[style] .sidebar-icon { opacity: 1; }

/* 移动端展开菜单时隐藏 logo 和底部 */
.sidebar.open .sidebar-brand,
.sidebar.open .sidebar-footer { display: none; }


/* ========== 响应式 ========== */

@media (max-width: 1200px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; padding: 32px 32px 48px; }
    .footer { margin-left: 200px; padding: 0 32px; }
    .search-section { padding: 40px 0 32px; }
    .search-header h1 { font-size: 26px; }
}

@media (max-width: 1024px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; padding: 28px 24px 40px; }
    .footer { margin-left: 200px; padding: 0 24px; }
    .footer-content { flex-direction: column; text-align: center; }
    .tools-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
    .search-section { padding: 32px 0 24px; }
    .search-header h1 { font-size: 24px; }
    .search-header p { font-size: 14px; }
    .search-container { max-width: 480px; }
    .tool-card { padding: 18px 14px; }
    .tool-card h3 { font-size: 13px; }
    .hot-tools { margin-bottom: 28px; }
    .category-group { margin-bottom: 22px; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 50px;
        left: 0;
        bottom: 0;
        width: max-content;
        min-width: 100px;
        max-width: 42vw;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 150;
        background: #fff;
        border-right: 1px solid rgba(0,0,0,0.06);
    }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.08); }
    .sidebar.open ~ .main-content,
    .sidebar.open ~ .footer { margin-left: min(42vw, 140px); }
    .main-content, .footer { transition: margin-left .25s ease; }
    .mobile-header { display: flex; }
    .main-content { margin-left: 0; padding: 20px 20px 40px; }
    .footer { margin-left: 0; padding: 0 20px; }
    .search-section { padding: 24px 0 20px; }
    .search-header { margin-bottom: 18px; }
    .search-header h1 { font-size: 22px; }
    .search-header p { font-size: 14px; }
    .search-container { max-width: 100%; }
    .search-txt { font-size: 16px; height: 44px; padding: 0 14px; }
    .search-engine-btn { padding: 6px 12px; font-size: 12px; }
    .tools-grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 8px; }
    .tool-card { padding: 16px 12px; border-radius: 10px; }
    .tool-card h3 { font-size: 13px; margin-bottom: 4px; }
    .tool-card p { font-size: 11px; }
    .category-title { padding: 6px 10px; gap: 8px; }
    .category-name { font-size: 13px; }
    .hot-tools { margin-bottom: 24px; }
    .footer { margin-top: 36px; }
    .footer-content { flex-direction: column; text-align: center; gap: 8px; }
}

@media (max-width: 480px) {
    .main-content { padding: 16px 16px 32px; }
    .search-section { padding: 16px 0 14px; }
    .search-header h1 { font-size: 20px; }
    .search-header p { font-size: 13px; }
    .tools-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .tool-card { padding: 14px 10px; }
    .tool-card h3 { font-size: 12px; }
    .tool-card p { font-size: 11px; line-height: 1.4; }
    .sidebar { min-width: 80px; max-width: 38vw; }
    .sidebar.open ~ .main-content,
    .sidebar.open ~ .footer { margin-left: min(38vw, 120px); }


@media (max-width: 380px) {
    .main-content { padding: 12px 12px 24px; }
    .search-section { padding: 12px 0 10px; }
    .search-header h1 { font-size: 18px; }
    .search-header p { font-size: 12px; }
    .tools-grid { gap: 8px; }
    .tool-card { padding: 12px 8px; }
    .tool-card h3 { font-size: 12px; }
    .tool-card p { font-size: 10px; -webkit-line-clamp: 1; }
    .sidebar { min-width: 72px; max-width: 35vw; }
    .sidebar.open ~ .main-content,
    .sidebar.open ~ .footer { margin-left: min(35vw, 105px); }
}
