/* --- 1. 全局设置 & 字体导入 --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');

:root {
    /* -- Light Mode Colors -- */
    --bg-color-light: #f0f2f5;
    --card-bg-light: rgba(255, 255, 255, 0.6);
    --text-color-light: #1c1c1e;
    --heading-color-light: #000000;
    --border-color-light: rgba(0, 0, 0, 0.1);
    --primary-gradient: linear-gradient(90deg, #007cf0, #00dfd8);
    --primary-gradient-hover: linear-gradient(90deg, #008cff, #00f5eb);

    /* -- Dark Mode Colors -- */
    --bg-color-dark: #121212;
    --card-bg-dark: rgba(28, 28, 30, 0.7);
    --text-color-dark: #e5e5e7;
    --heading-color-dark: #ffffff;
    --border-color-dark: rgba(255, 255, 255, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* --- 2. 统一样式，为背景做准备 --- */
body {
    font-family: 'Poppins', sans-serif;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
    /* 强制body背景为我们的基础色 */
    background-color: var(--bg-color-dark);
}
body.light-mode {
    background-color: var(--bg-color-light);
    color: var(--text-color-light);
}
body.dark-mode {
    color: var(--text-color-dark);
}

/* --- 3. 封装好的、100%有效的星空背景 --- */
.background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}
.glow-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120vmax;
    height: 120vmax;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, hsla(230, 80%, 30%, 0.3), transparent 65%);
    animation: pulse-glow 12s ease-in-out infinite alternate;
    transition: background 0.5s;
}
.light-mode .glow-layer {
    background: radial-gradient(circle, hsla(220, 80%, 70%, 0.2), transparent 65%);
}
@keyframes pulse-glow {
    from { opacity: 0.6; transform: translate(-50%, -50%) scale(0.9); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
}
.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-repeat: repeat;
    transition: opacity 0.3s;
}
.stars.layer1 {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cdefs%3E%3Cstyle%3E.a%7Bfill:white;opacity:0.6;%7D%3C/style%3E%3C/defs%3E%3Ccircle class='a' cx='50' cy='150' r='1'/%3E%3Ccircle class='a' cx='350' cy='50' r='1'/%3E%3Ccircle class='a' cx='150' cy='300' r='1'/%3E%3Ccircle class='a' cx='250' cy='200' r='1'/%3E%3C/svg%3E");
    animation: move-stars 60s linear infinite;
}
.stars.layer2 {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cdefs%3E%3Cstyle%3E.a%7Bfill:white;opacity:0.8;%7D%3C/style%3E%3C/defs%3E%3Ccircle class='a' cx='100' cy='100' r='1.5'/%3E%3Ccircle class='a' cx='300' cy='250' r='1.5'/%3E%3Ccircle class='a' cx='200' cy='50' r='1.5'/%3E%3C/svg%3E");
    animation: move-stars 45s linear infinite;
}
.stars.layer3 {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cdefs%3E%3Cstyle%3E.a%7Bfill:white;opacity:1;%7D%3C/style%3E%3C/defs%3E%3Ccircle class='a' cx='200' cy='200' r='2'/%3E%3Ccircle class='a' cx='50' cy='350' r='2'/%3E%3C/svg%3E");
    animation: move-stars 30s linear infinite;
}
@keyframes move-stars {
    from { transform: translateY(0); }
    to { transform: translateY(-400px); }
}
.light-mode .stars { opacity: 0.5; }


/* --- 4. 最终优化版 - 导航栏与多级菜单样式 --- */
.main-header {
    position: fixed; top: 0; left: 0; width: 100%; padding: 0 5%; height: 70px;
    display: flex; justify-content: space-between; align-items: center;
    z-index: 100; backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%); transition: background-color 0.3s;
}
.light-mode .main-header { background-color: rgba(255, 255, 255, 0.5); border-bottom: 1px solid var(--border-color-light); }
.dark-mode .main-header { background-color: rgba(20, 20, 22, 0.6); border-bottom: 1px solid var(--border-color-dark); }

.logo a {
    font-size: 24px; font-weight: 700; text-decoration: none;
    background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.main-nav { display: flex; align-items: center; gap: 30px; }
.main-nav > ul { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 30px; }
.main-nav ul li { position: relative; }

.main-nav a {
    font-size: 16px; text-decoration: none;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0; position: relative; transition: all 0.3s;
}
.light-mode .main-nav a { color: #333; }
.dark-mode .main-nav a { color: #eee; }
.main-nav a::after { display: none; }

/* 修正：仅在鼠标悬停时，将文字和图标变为渐变色，不再添加背景块 */
.main-nav a:hover, .main-nav a:hover i {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.main-nav > ul > li > a.active::after,
.main-nav .has-submenu > a.active-parent::after {
    content: ''; position: absolute; bottom: 0; left: 0; width: 100%; height: 2px;
    background: var(--primary-gradient); display: block; animation: fadeIn 0.3s;
}
.main-nav .has-submenu > a.active-parent {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- 倒三角旋转动画 & Bug修复 --- */
.main-nav .menu-category .ph-caret-down {
    transition: transform 0.3s ease;
    backface-visibility: hidden; /* 修正：增加此行防止旋转时图标消失 */
}
.has-submenu:hover > .menu-category .ph-caret-down {
    transform: rotate(180deg);
}

/* --- 子菜单 (Submenu) 样式 --- */
.submenu {
    list-style: none; margin: 0; padding: 8px 0; position: absolute;
    top: calc(100% + 5px); left: 50%;
    transform: translateX(-50%) translateY(10px);
    min-width: 240px; border-radius: 12px; z-index: 10;
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid;
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}
.light-mode .submenu { background-color: rgba(255, 255, 255, 0.7); border-color: var(--border-color-light); box-shadow: 0 8px 30px rgba(0,0,0,0.12); }
.dark-mode .submenu { background-color: rgba(28, 28, 30, 0.75); border-color: var(--border-color-dark); box-shadow: 0 8px 30px rgba(0,0,0,0.25); }

.has-submenu:hover > .submenu {
    opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0);
}

.submenu li a {
    padding: 10px 20px;
    margin: 2px 8px; /* 调整内外边距，让胶囊更好看 */
    border-radius: 6px;
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s;
}
.submenu li a i { font-size: 18px; opacity: 0.7; }

/* 子菜单当前页面的高亮 (active 状态) */
.submenu li a.active {
    background: var(--primary-gradient);
}
.submenu li a.active, .submenu li a.active i {
    color: white !important;
    -webkit-text-fill-color: white;
    opacity: 1;
}

/* 子菜单悬停时 (但仅限非active状态的链接)，文字和图标变成渐变色 */
.submenu li a:not(.active):hover, 
.submenu li a:not(.active):hover i {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 1;
}


/* --- 5. 主内容 & 玻璃卡片 --- */
.main-content {
    padding: 120px 20px 50px; display: flex; justify-content: center;
    position: relative; z-index: 1; /* 确保内容在背景之上 */
}
.container {
    width: 100%; max-width: 850px; padding: 40px; border-radius: 16px;
    backdrop-filter: blur(12px) saturate(180%); -webkit-backdrop-filter: blur(12px) saturate(180%);
    transition: background-color 0.3s, border 0.3s; animation: fadeIn 0.8s ease-out;
}

/* 新增：为首页准备的宽版容器 */
.container.container-wide {
    max-width: 1400px; /* 您可以根据喜好调整这个值，1200px 到 1400px 都是不错的选择 */
}

.light-mode .container { /* ... */ }



.light-mode .container { background-color: var(--card-bg-light); border: 1px solid var(--border-color-light); }
.dark-mode .container { background-color: var(--card-bg-dark); border: 1px solid var(--border-color-dark); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.page-title h1 { font-size: 36px; font-weight: 700; text-align: center; margin-bottom: 15px; }
.light-mode .page-title h1 { color: var(--heading-color-light); }
.dark-mode .page-title h1 { color: var(--heading-color-dark); }
.page-title p { font-size: 18px; text-align: center; margin-bottom: 40px; max-width: 600px; margin-left: auto; margin-right: auto; }


/* --- 5.5 主页搜索框样式 (已优化) --- */
.search-container {
    /* 关键改动：增加下外边距，把它和下面的卡片分开 */
    margin-bottom: 60px; 
    display: flex;
    justify-content: center;
    padding: 0 20px; /* 在移动端屏幕边缘留出一些空间 */
}

.search-box {
    position: relative;
    width: 100%;
    /* 关键改动：设置一个合理的最大宽度，让它不会过长 */
    max-width: 700px; 
}

.search-box i {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    opacity: 0.5;
    transition: all 0.3s ease; /* 给图标也加上过渡效果 */
    pointer-events: none; /* 防止图标干扰点击 */
}

#tool-search {
    width: 100%;
    padding: 16px 20px 16px 55px;
    border-radius: 12px;
    font-size: 16px;
    font-family: 'Poppins', sans-serif;
    border: 1px solid;
    /* 关键改动：让背景色与主题更融合 */
    background-color: transparent; 
    transition: all 0.3s;
}
.light-mode #tool-search {
    border-color: var(--border-color-light);
    color: var(--text-color-light);
}
.dark-mode #tool-search {
    border-color: var(--border-color-dark);
    color: var(--text-color-dark);
}
#tool-search:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 124, 240, 0.4);
    border-color: #007cf0;
    /* 聚焦时给一点背景色，感觉更实体化 */
    background-color: rgba(0, 124, 240, 0.05);
}
#tool-search:focus + i {
    opacity: 1;
    /* 图标颜色与渐变色统一 */
    color: #007cf0; 
}


/* --- 6. 现代化表单 --- */
.form-grid { display: grid; gap: 25px; }
label { font-weight: 600; font-size: 14px; text-align: left; }
input, select, textarea, pre {
    width: 100%; padding: 14px 16px; border-radius: 8px; font-size: 16px;
    font-family: 'Poppins', sans-serif; border: 1px solid; background-color: transparent; transition: all 0.3s;
}
.light-mode input, .light-mode select, .light-mode textarea, .light-mode pre { border-color: var(--border-color-light); color: var(--text-color-light); }
.dark-mode input, .dark-mode select, .dark-mode textarea, .dark-mode pre { border-color: var(--border-color-dark); color: var(--text-color-dark); }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 3px rgba(0, 124, 240, 0.3); border-color: #007cf0; }
textarea, pre { white-space: pre-wrap; word-break: break-all; resize: vertical; min-height: 180px; font-family: 'Fira Code', 'Courier New', monospace; }

/* --- 7. 渐变按钮 & 加载动画 --- */
.button-group { display: flex; flex-wrap: wrap; gap: 15px; justify-content: center; margin-top: 15px; }
.btn { padding: 14px 30px; border-radius: 8px; border: none; font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s; position: relative; overflow: hidden; }
.btn-gradient { background: var(--primary-gradient); color: white; }
.btn-gradient:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(0, 175, 230, 0.3); }
.btn-secondary { border: 1px solid; }
.light-mode .btn-secondary { background: rgba(255,255,255,0.2); border-color: var(--border-color-light); color: var(--text-color-light); }
.dark-mode .btn-secondary { background: rgba(0,0,0,0.2); border-color: var(--border-color-dark); color: var(--text-color-dark); }
.btn-secondary:hover { background-color: rgba(0,0,0,0.1); }
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.3); border-top-color: #fff; border-radius: 50%; animation: btn-spin 0.8s linear infinite; margin: 0 auto; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* --- 8. 主页工具卡片 (最终修复版 - 彻底解决对齐问题) --- */
.tool-cards { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px; 
}

/* 核心改动 1: 让卡片填满其父级 <a> 标签 */
.card { 
    padding: 30px; 
    border-radius: 12px; 
    text-align: left; 
    transition: all 0.3s ease; 
    position: relative; 
    overflow: hidden;

    /* 让 .card 的高度 100% 填充其父元素 <a> */
    height: 100%; 
    
    /* 将 .card 自身设置为 Flex 容器，以便控制其内部元素 */
    display: flex;
    flex-direction: column;
}
.light-mode .card { background: rgba(255,255,255,0.3); border: 1px solid var(--border-color-light); }
.dark-mode .card { background: rgba(30,30,32,0.5); border: 1px solid var(--border-color-dark); }
.card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.1); }

/* 核心改动 2: .card-content 现在也需要是 Flex 容器 */
/* 这是因为您的 HTML 中，所有内容都在 .card-content 里 */
.card .card-content {
    display: flex;
    flex-direction: column;
    /* 让它也填满 .card 的可用空间 */
    flex-grow: 1; 
}

.card .icon { 
    font-size: 48px; 
    background: var(--primary-gradient); 
    -webkit-background-clip: text; 
    -webkit-text-fill-color: transparent; 
    margin-bottom: 15px; 
}

.card h2 { 
    font-size: 22px; 
    margin-bottom: 10px;
}
.light-mode .card h2 { color: var(--heading-color-light); }
.dark-mode .card h2 { color: var(--heading-color-dark); }

/* 核心改动 3: 让描述文字 <p> 自动伸缩，填满多余空间 */
.card p { 
    font-size: 15px; 
    line-height: 1.6; 
    margin-bottom: 20px;

    /* 魔法核心！它会占据所有可用的垂直空间 */
    flex-grow: 1;
}

/* 核心改动 4: 确保按钮不被拉伸 */
.card .btn-gradient {
    flex-shrink: 0;
}

/* --- 9. 页脚 & 暗黑模式切换器 --- */
footer { text-align: center; padding: 40px 20px 20px; color: #888; }
footer a { background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 600; text-decoration: none; }
.theme-switcher { cursor: pointer; font-size: 24px; }

/* --- 10. Toast 提示 --- */
#toast { position: fixed; bottom: -100px; left: 50%; transform: translateX(-50%); padding: 12px 25px; border-radius: 8px; color: white; background: #333; box-shadow: 0 4px 15px rgba(0,0,0,0.2); transition: bottom 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); z-index: 2000; }
#toast.show { bottom: 30px; }

/* --- 11. 全新的自定义下拉框样式 --- */
.custom-select-wrapper { position: relative; font-family: 'Poppins', sans-serif; }
.custom-select-wrapper select { display: none; }
.select-selected { border-radius: 8px; padding: 14px 40px 14px 16px; cursor: pointer; position: relative; user-select: none; transition: all 0.3s; border: 1px solid; }
.light-mode .select-selected { background-color: transparent; border-color: var(--border-color-light); color: var(--text-color-light); }
.dark-mode .select-selected { background-color: transparent; border-color: var(--border-color-dark); color: var(--text-color-dark); }
.select-selected:hover { border-color: #007cf0; }
.select-selected::after { content: ""; position: absolute; top: 50%; right: 18px; transform: translateY(-50%); width: 0; height: 0; border: 6px solid transparent; transition: transform 0.3s ease; }
.light-mode .select-selected::after { border-top-color: #333; }
.dark-mode .select-selected::after { border-top-color: #eee; }
.select-selected.select-arrow-active::after { transform: translateY(-50%) rotate(180deg); }
.select-items { position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 99; border-radius: 12px; overflow: hidden; backdrop-filter: blur(12px) saturate(180%); -webkit-backdrop-filter: blur(12px) saturate(180%); max-height: 250px; overflow-y: auto; border: 1px solid; }
.light-mode .select-items { background-color: var(--card-bg-light); border-color: var(--border-color-light); }
.dark-mode .select-items { background-color: var(--card-bg-dark); border-color: var(--border-color-dark); }
.select-hide { display: none; }
.select-items div { padding: 12px 16px; cursor: pointer; transition: all 0.2s; }
.light-mode .select-items div:hover, .light-mode .same-as-selected { background-color: rgba(0, 124, 240, 0.1); }
.dark-mode .select-items div:hover, .dark-mode .same-as-selected { background-color: rgba(0, 124, 240, 0.2); }








/* --- 13. 导航栏布局修正与新下拉框样式 (已修复断层问题) --- */

/* 核心修正：让 <ul> 成为 Flex 容器，使其子元素 <li> 水平排列 */
.main-nav > ul {
    display: flex; align-items: center; gap: 30px;
    list-style: none; margin: 0; padding: 0;
}
.main-nav > ul > li {
    display: flex; align-items: center;
}
.nav-separator {
    width: 1px; height: 20px; background-color: var(--border-color-dark);
    margin: 0 -15px;
}
.light-mode .nav-separator { background-color: var(--border-color-light); }

/* --- 下拉式语言切换器 --- */
.lang-dropdown {
    position: relative;
    /* 修复方案 1: 给整个容器增加一个看不见的“桥” */
    padding-bottom: 10px;
    margin-bottom: -10px;
}

.lang-dropdown-btn {
    display: flex; align-items: center; gap: 8px; background-color: transparent;
    border: none; border-radius: 8px; padding: 8px 12px;
    font-family: 'Poppins', sans-serif; font-size: 14px;
    font-weight: 600; color: var(--text-color-dark);
    cursor: pointer; transition: all 0.3s;
}
.light-mode .lang-dropdown-btn { color: var(--text-color-light); }
.lang-dropdown-btn:hover { background-color: rgba(0, 124, 240, 0.1); }
.lang-dropdown-btn i { font-size: 18px; }
.lang-dropdown-btn .dropdown-arrow {
    font-size: 12px; opacity: 0.6; transition: transform 0.3s ease;
}

.lang-dropdown-content {
    display: block; /* 默认就是 block，我们用其他方式控制显隐 */
    position: absolute; top: calc(100% - 2px); /* 向上移动一点，与“桥”重叠 */
    right: 0; min-width: 120px; border: 1px solid var(--border-color-dark);
    border-radius: 12px; z-index: 10; padding: 8px;
    backdrop-filter: blur(16px) saturate(180%); -webkit-backdrop-filter: blur(16px) saturate(180%);
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    
    /* 修复方案 2: 用 opacity 和 visibility 控制显隐 */
    opacity: 0;
    transform: translateY(10px);
    visibility: hidden;
    pointer-events: none; /* 隐藏时不可点击 */
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s; /* 延迟隐藏visibility */
}
.light-mode .lang-dropdown-content { background-color: rgba(255, 255, 255, 0.8); border-color: var(--border-color-light); box-shadow: 0 8px 30px rgba(0,0,0,0.12); }
.dark-mode .lang-dropdown-content { background-color: rgba(28, 28, 30, 0.8); }

/* 核心：现在当鼠标悬停在整个容器上时，改变子元素的样式来显示它 */
.lang-dropdown:hover .lang-dropdown-content {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* 显示时可点击 */
    transform: translateY(0);
    transition-delay: 0s; /* 立即开始显示动画 */
}
.lang-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.lang-dropdown-content a {
    display: block; padding: 10px 12px; border-radius: 6px;
    font-weight: 500; text-decoration: none;
}
.lang-dropdown-content a.active {
    background: var(--primary-gradient); color: white !important;
    -webkit-text-fill-color: white;
}
.lang-dropdown-content a:not(.active):hover {
    background-color: rgba(0, 124, 240, 0.2);
}