:root {
    --primary: #4a90e2;
    --bg: #f4f6f8;
    --white: #fff;
    --border: #e0e0e0;
    --header-h: 60px; /* 顶部导航栏高度 */
    --text: #333;
    --hover-bg: #f0f7ff;
    --active-bg: #e1effe;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    /* 关键修改：移除 min-height: 100vh 的强制限制，防止布局锁死 */
    padding-top: var(--header-h); 
    display: flex;
    flex-direction: column;
}

/* --- Header 样式 --- */
header {
    height: var(--header-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px; /* 稍微减小内边距适配手机 */
}

.logo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-decoration: none;
    flex-shrink: 0;
}

/* 导航菜单 (PC端) */
.nav-menu {
    display: flex;
    gap: 20px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.nav-link {
    text-decoration: none;
    color: #666;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 12px;
    border-radius: 4px;
    transition: 0.2s;
    white-space: nowrap;
}
.nav-link:hover, .nav-link.active {
    color: var(--primary);
    background: var(--hover-bg);
}

/* 右侧控制区 */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.lang-selector {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 0.8rem;
    background: #fff;
    max-width: 90px;
}
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
    padding: 5px;
}
.hamburger span {
    width: 22px;
    height: 2px;
    background: #333;
}

/* --- 布局核心 (Layout) --- */
.layout {
    display: flex;
    flex: 1;
    /* PC端保持全屏高度，内部滚动 */
    height: calc(100vh - var(--header-h)); 
    overflow: hidden; 
}

.sidebar-left {
    width: 250px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.main-content {
    flex: 1;
    background: var(--white);
    overflow-y: auto; /* PC端内容区独立滚动 */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 组件样式 */
.country-grid {
    padding: 5px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); /* 自适应列宽 */
    gap: 2px;
    align-content: start;
}
.country-item {
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 6px;
}
.country-item:hover { background: var(--hover-bg); }
.country-item.active { background: var(--active-bg); border-color: var(--primary); }
.flag { font-size: 1.4rem; }
.country-name { font-size: 0.75rem; text-align: center; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; padding: 0 2px; }

.text-area-wrapper { border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
textarea { width: 100%; border: none; resize: vertical; font-size: 1rem; height: 150px; font-family: inherit; }

.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.voice-item { border: 1px solid var(--border); border-radius: 6px; padding: 8px; text-align: center; cursor: pointer; }
.voice-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.voice-emoji { font-size: 1.5rem; display: block; margin-bottom: 2px; }
.voice-name { font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* 情感标签与滑块 */
.style-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.style-chip { display: flex; align-items: center; gap: 5px; border: 1px solid #ccc; border-radius: 15px; padding: 4px 10px; font-size: 0.85rem; cursor: pointer; }
.style-chip.active { background: var(--active-bg); border-color: var(--primary); color: var(--primary); font-weight: bold; }
.style-play-btn { background: none; border: none; cursor: pointer; padding: 2px 4px; font-size: 0.8rem; opacity: 0.6; }
.style-play-btn:hover { opacity: 1; transform: scale(1.1); }

.slider-row { display: flex; gap: 20px; margin-top: 15px; padding-top: 15px; border-top: 1px dashed #ddd; flex-wrap: wrap; }
.slider-item { flex: 1; min-width: 120px; }

.btn-primary { background: var(--primary); color: #fff; width: 100%; padding: 12px; font-size: 1rem; font-weight: 700; border: none; border-radius: 6px; margin-top: 20px; cursor: pointer; }
.btn-secondary { background: #eee; color: #555; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }

/* 结果区 */
#result-area { margin-top: 20px; background: #e8f5e9; padding: 15px; border-radius: 8px; border: 1px solid #c8e6c9; display: none; }
audio { width: 100%; margin-top: 10px; }

/* =========================================
   🔴 移动端响应式核心修复 (max-width: 900px)
   ========================================= */
@media (max-width: 900px) {
    /* 1. 解除高度锁定，允许页面自由滚动 */
    .layout {
        flex-direction: column;
        height: auto; /* 不再是 100vh */
        overflow: visible; /* 允许溢出滚动 */
        display: block; /* 改为块级布局，避免 flex 挤压 */
    }

    /* 2. 左侧边栏变更为顶部横向滚动栏，或者折叠列表 */
    .sidebar-left {
        width: 100%;
        height: auto;
        max-height: 180px; /* 限制高度，避免占据太多屏幕 */
        border-right: none;
        border-bottom: 1px solid #eee;
        overflow-y: auto; /* 允许内部滚动 */
    }
    
    .country-grid {
        /* 在手机上让国家列表更紧凑 */
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        padding: 10px;
    }

    /* 3. 主内容区 */
    .main-content {
        height: auto;
        overflow: visible; /* 允许内容撑开高度 */
        padding: 15px;
        padding-bottom: 60px; /* 底部留白，防止被浏览器底栏遮挡 */
    }

    /* 4. 导航菜单改为全屏抽屉或下拉 */
    .nav-menu {
        position: fixed;
        top: var(--header-h);
        left: 0;
        width: 100%;
        background: #fff;
        flex-direction: column;
        gap: 0;
        padding: 0;
        border-bottom: 1px solid #ddd;
        transform: translateY(-150%); /* 默认隐藏 */
        transition: transform 0.3s ease-in-out;
        z-index: 998;
        box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    }
    
    .nav-menu.active {
        transform: translateY(0); /* 显示 */
    }

    .nav-link {
        width: 100%;
        text-align: center;
        padding: 15px;
        border-bottom: 1px solid #f0f0f0;
        display: block;
    }

    /* 5. 显示汉堡按钮 */
    .hamburger {
        display: flex;
    }
    
    /* 6. 调整文本框高度 */
    textarea {
        height: 120px;
    }
}