/* style.css */

/* --- 全局变量与重置 --- */
:root {
    --bg-color: #faf9de;       
    --header-bg: #ffffff;      
    --text-color: #333333;
    --primary-color: #5d4037;  
    --accent-color: #8d6e63;   
    --hover-color: #efebe9;    
    --footer-bg: #4e342e;      
    --footer-text: #d7ccc8;    
    --nav-height: 60px;
    --sidebar-width: 250px;
    --highlight-color: #d7ccc8;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.8;
    padding-top: var(--nav-height);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; transition: 0.3s; }
ul { list-style: none; }

h1, h2, h3 {
    scroll-margin-top: calc(var(--nav-height) + 20px);
}

/* --- 顶部菜单栏 --- */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--nav-height);
    background: var(--header-bg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between; 
    padding: 0 20px;
}

.header-left-group {
    display: flex;
    align-items: center;
    gap: 20px; /* Logo 和音效组之间的间距 */
    z-index: 1100;
}

.logo {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- 音效控制组件 --- */
.sound-wrapper {
    display: flex;
    align-items: center;
    background-color: #f5f5f5;
    border-radius: 20px;
    padding: 2px 5px;
    border: 1px solid #e0e0e0;
}

.sound-btn {
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.sound-btn:hover {
    background-color: #e0e0e0;
}

.sound-selector {
    position: relative;
    display: flex;
    align-items: center;
    border-left: 1px solid #ccc;
    margin-left: 5px;
    padding-left: 5px;
}

.sound-arrow {
    cursor: pointer;
    font-size: 0.7rem;
    color: #666;
    padding: 4px 6px;
    border-radius: 4px;
    transition: 0.2s;
    user-select: none;
}

.sound-arrow:hover {
    background-color: #e0e0e0;
    color: var(--primary-color);
}

/* 音效下拉菜单 */
.sound-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    min-width: 120px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 6px;
    display: none; /* JS 控制显示 */
    border: 1px solid #eee;
    z-index: 1200;
    padding: 5px 0;
}

/* 小三角形 */
.sound-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #fff transparent;
}

.sound-dropdown.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

.sound-dropdown li {
    padding: 8px 15px;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sound-dropdown li:hover {
    background-color: var(--hover-color);
    color: var(--primary-color);
}

/* 选中状态 */
.sound-dropdown li.active {
    font-weight: bold;
    color: var(--primary-color);
    background-color: #fafafa;
}

.sound-dropdown li.active::after {
    content: '✓';
    font-size: 0.8rem;
    margin-left: 8px;
}

/* --- 桌面端导航 --- */
.nav-container { display: flex; align-items: center; }
.nav-menu { display: flex; gap: 5px; }
.nav-item { position: relative; padding: 0 10px; }

.nav-link {
    display: block;
    line-height: var(--nav-height);
    color: #555;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 10px;
}

.nav-link:hover, .nav-item:hover > .nav-link {
    color: var(--primary-color);
    background-color: var(--hover-color);
}

/* 【新增】二级菜单打开时，顶级项保持高亮（不影响其它功能） */
.nav-item.open > .nav-link {
    color: var(--primary-color);
    background-color: var(--hover-color);
}

/* 二级菜单 */
.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 0 0 4px 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 1100;
    max-height: calc(100vh - var(--nav-height) - 20px);
    overflow-y: auto;
}

.dropdown::-webkit-scrollbar { width: 6px; }
.dropdown::-webkit-scrollbar-track { background: #f1f1f1; }
.dropdown::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* 【修改】二级菜单不再用 hover 控制显示，改为 JS 加 open 类控制 */
.nav-item.open .dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown li { position: relative; }

.dropdown li a {
    display: block;
    padding: 12px 15px;
    font-size: 0.9rem;
    color: #666;
    border-bottom: 1px solid #f5f5f5;
    white-space: nowrap;
}

.dropdown li a:hover, .dropdown li:hover > a {
    background-color: var(--hover-color);
    color: var(--primary-color);
}

/* 三级菜单 */
.submenu {
    display: none;
    background-color: #fafafa;
    list-style: none;
    padding-left: 0;
    border-left: 3px solid var(--accent-color);
}

/* 【修改】三级菜单不再用 hover 让整个 dropdown 展开，改为仅展开当前二级项 */
.dropdown li.has-submenu.submenu-open > .submenu {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* 【新增】当前展开的二级菜单项高亮（仅样式，不影响逻辑） */
.dropdown li.has-submenu.submenu-open > .submenu-trigger {
    background-color: var(--hover-color);
    color: var(--primary-color);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(5px); }
    to { opacity: 1; transform: translateX(0); }
}

.submenu li a {
    padding-left: 30px;
    font-size: 0.85rem;
    color: #777;
    border-bottom: none;
}
.submenu li a:hover { background-color: #eee; }

/* 移动端菜单按钮 */
.hamburger {
    display: none;
    cursor: pointer;
    flex-direction: column;
    gap: 5px;
    padding: 5px;
    z-index: 1100;
}
.hamburger span {
    display: block;
    width: 25px;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 2px;
    transition: 0.3s;
}

/* --- 收藏提示弹窗 --- */
.bookmark-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    background-color: #fff;
    border-left: 5px solid #ffca28;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    padding: 15px 20px;
    border-radius: 4px;
    z-index: 2000;
    display: none;
    animation: slideIn 0.5s ease-out;
    max-width: 300px;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

.toast-content { display: flex; align-items: flex-start; gap: 15px; }
.toast-icon { font-size: 1.5rem; }
.toast-text p { font-size: 0.9rem; color: #555; margin-bottom: 5px; line-height: 1.4; text-align: left; }
.key-shortcut { background: #eee; padding: 2px 6px; border-radius: 3px; font-family: monospace; border: 1px solid #ccc; font-size: 0.85rem; }

#bookmark-ok-btn {
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    padding: 5px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 5px;
    align-self: flex-end;
    transition: 0.2s;
}
#bookmark-ok-btn:hover { background-color: var(--accent-color); }

/* --- 布局容器 --- */
.container { display: flex; max-width: 1200px; margin: 0 auto; flex: 1; width: 100%; }

/* --- 侧边栏 --- */
aside {
    width: var(--sidebar-width);
    background-color: rgba(255, 255, 255, 0.4);
    border-right: 1px solid rgba(0,0,0,0.03);
    padding: 20px;
    position: fixed;
    top: var(--nav-height);
    bottom: 0;
    overflow-y: auto;
    scrollbar-width: thin; 
}

aside h3.toc-title {
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 5px;
}

#toc-list li { margin-bottom: 8px; }
#toc-list .toc-h2 { font-size: 0.9rem; font-weight: 600; display: block; padding: 4px 0; }
#toc-list .toc-h3 { font-size: 0.85rem; padding-left: 15px; color: #666; border-left: 2px solid transparent; display: block; padding: 2px 0 2px 15px; }
#toc-list a:hover { color: var(--primary-color); }
#toc-list .toc-h3:hover { border-left-color: var(--accent-color); }

/* --- 正文 --- */
main { flex: 1; margin-left: var(--sidebar-width); padding: 40px; max-width: 900px; }
main h1 { font-size: 2rem; margin-bottom: 20px; color: var(--primary-color); }
main h2 { font-size: 1.5rem; margin-top: 30px; margin-bottom: 15px; border-left: 5px solid var(--accent-color); padding-left: 10px; }
main h3 { font-size: 1.2rem; margin-top: 20px; margin-bottom: 10px; color: #555; }
main p { margin-bottom: 15px; text-align: justify; font-size: 1.1rem; }
main img { display: block; margin: 30px auto; max-width: 100%; height: auto; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }

/* --- 单词交互 --- */
.click-word { cursor: pointer; border-bottom: 1px dotted #999; transition: background-color 0.2s; }
.click-word:hover { background-color: var(--highlight-color); color: #000; border-bottom-style: solid; }

#translation-tooltip {
    position: absolute;
    background: rgba(50, 50, 50, 0.95);
    color: #fff;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 2000;
    display: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    pointer-events: none;
    white-space: nowrap;
}
#translation-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: rgba(50, 50, 50, 0.95) transparent transparent transparent;
}

/* --- Footer --- */
.site-footer { background-color: var(--footer-bg); color: var(--footer-text); padding: 40px 20px 20px; margin-top: auto; z-index: 100; position: relative; }
.footer-content { max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 30px; padding-bottom: 30px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.footer-section { flex: 1; min-width: 250px; }
.footer-section h4 { color: #fff; font-size: 1.1rem; margin-bottom: 15px; position: relative; padding-bottom: 8px; }
.footer-section h4::after { content: ''; position: absolute; left: 0; bottom: 0; width: 40px; height: 2px; background-color: var(--accent-color); }
.footer-section p { font-size: 0.9rem; line-height: 1.6; color: #d7ccc8; margin-bottom: 10px; }
.footer-links li { margin-bottom: 8px; }
.footer-links a { color: #d7ccc8; font-size: 0.9rem; transition: 0.3s; }
.footer-links a:hover { color: #fff; padding-left: 5px; }
.footer-bottom { text-align: center; padding-top: 20px; font-size: 0.85rem; color: rgba(255,255,255,0.6); }

/* --- 响应式 --- */
@media (max-width: 768px) {
    .container { flex-direction: column; }
    aside { position: relative; width: 100%; top: 0; border-right: none; border-bottom: 1px solid #ddd; padding: 15px; max-height: fit-content; z-index: 1; }
    main { margin-left: 0; padding: 20px; }
    .hamburger { display: flex; }
    /* ZhaoKaifeng.com All rights reserved. */
    .nav-container { position: absolute; top: var(--nav-height); right: 0; left: auto; width: auto; padding-right: 15px; pointer-events: none; }
    .nav-menu { flex-direction: column; gap: 0; background: #fff; min-width: 200px; max-height: 80vh; overflow-y: auto; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,0.15); padding: 5px 0; opacity: 0; visibility: hidden; transform: translateY(-10px) scale(0.95); transform-origin: top right; transition: all 0.3s, visibility 0.3s; pointer-events: auto; }
    .nav-menu.active { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
    .nav-item { width: 100%; text-align: left; border-bottom: none; }
    .nav-link { line-height: 40px; padding: 0 20px; font-size: 0.95rem; }
    .nav-link:hover { background-color: #f5f5f5; color: var(--primary-color); }
    
    .dropdown { position: static; box-shadow: none; opacity: 1; visibility: visible; transform: none; background-color: #fafafa; display: none; padding-left: 10px; max-height: none; overflow-y: visible; }

    /* 【修改】移动端二级菜单同样改为 open 类控制显示 */
    .nav-item.open > .dropdown { display: block; }

    .dropdown li a { border-bottom: none; padding: 8px 20px; font-size: 0.85rem; }

    /* 【修改】移动端三级菜单展开逻辑与桌面一致 */
    .dropdown li.has-submenu.submenu-open > .submenu { display: block; border-left: 2px solid #ddd; }
    
    .footer-content { flex-direction: column; gap: 20px; }
}
