/* =========================================
   1. 核心视觉系统 (Visual Design System)
   ========================================= */
:root {
    /* 主题色：学术蓝 + 专注灰 */
    --primary: #2563eb;       /* 主操作色 */
    --primary-dark: #1e40af;
    --primary-light: #eff6ff;

    /* 功能色 */
    --accent: #f59e0b;        /* 强调/高亮 */
    --success: #10b981;       /* 成功/保存 */
    --danger: #ef4444;        /* 删除/停止 */
    --text-main: #1e293b;     /* 正文黑 */
    --text-sub: #475569;      /* 辅助灰 */
    --text-placeholder: #94a3b8;

    /* 填空槽位 (Edit Mode) */
    --slot-bg: #f0f9ff;
    --slot-text: #0ea5e9;
    --slot-border: #bae6fd;
    --slot-hover-bg: #e0f2fe;
    --slot-active-bg: #0ea5e9;
    --slot-active-text: #ffffff;

    /* 界面参数 */
    --header-h: 64px;
    --radius: 10px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; outline: none; }

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: #f8fafc;
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* =========================================
   2. 顶部导航栏 (Header)
   ========================================= */
header {
    height: var(--header-h);
    background: rgba(255,255,255,0.98);
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    z-index: 50;
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand span {
    background: var(--primary);
    color: white;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.header-controls {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* 模式切换滑块 */
.mode-toggle {
    background: #f1f5f9;
    border-radius: 20px;
    padding: 4px;
    display: flex;
    position: relative;
    cursor: pointer;
    width: 220px;
    height: 40px;
    border: 1px solid #e2e8f0;
}
.toggle-item {
    flex: 1;
    text-align: center;
    line-height: 30px;
    z-index: 2;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
    transition: color 0.3s;
}
.toggle-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: 30px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 1;
}
/* 状态激活 */
body.mode-read .toggle-slider { transform: translateX(100%); }
body.mode-read .toggle-read { color: var(--primary); }
body.mode-edit .toggle-edit { color: var(--primary); }

/* 通用按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 4px rgba(37,99,235,0.2); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost { background: transparent; color: var(--text-sub); border: 1px solid #cbd5e1; }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); background: #f8fafc; }

.btn-danger { background: #fee2e2; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fecaca; }

.btn-save { background: var(--success); color: white; }
.btn-save:hover { filter: brightness(0.9); }

/* =========================================
   3. 主体布局 (Main Layout)
   ========================================= */
main {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr 420px; /* 左：语料 | 中：写作 | 右：真题 */
    gap: 20px;
    padding: 20px;
    overflow: hidden;
}

.panel {
    background: white;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.3s;
}
.panel:hover { box-shadow: var(--shadow-md); }

.panel-head {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.95rem;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    position: relative;
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =========================================
   4. 左侧：语料推荐 (Knowledge Base)
   ========================================= */
#kb-empty-state {
    text-align: center;
    color: var(--text-placeholder);
    margin-top: 60px;
    line-height: 1.8;
}

.opt-group { margin-bottom: 24px; }
.opt-title {
    font-size: 0.75rem;
    color: var(--text-sub);
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.opt-title::before { content: ""; width: 4px; height: 12px; background: var(--accent); border-radius: 2px; }

.opt-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-left: 3px solid transparent;
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}
.opt-card:hover {
    border-color: var(--primary);
    border-left-color: var(--primary);
    transform: translateX(4px);
    background: #f8fafc;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.opt-en { font-weight: 600; color: var(--text-main); font-size: 0.95rem; line-height: 1.4; margin-bottom: 4px; }
.opt-cn { font-size: 0.8rem; color: var(--text-sub); }

.opt-tag {
    position: absolute;
    top: 10px; right: 10px;
    font-size: 0.7rem; padding: 2px 6px; border-radius: 4px;
    font-weight: 600;
}
.tag-hot { background: #fee2e2; color: #b91c1c; }
.tag-safe { background: #dcfce7; color: #15803d; }
.tag-adv { background: #fef3c7; color: #b45309; }

/* =========================================
   5. 中间：写作工作台 (Workspace)
   ========================================= */
.tpl-selector {
    display: flex;
    gap: 10px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
}
.tpl-btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-sub);
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.2s;
}
.tpl-btn.active { background: white; color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

.paper-section {
    margin-bottom: 30px;
    position: relative;
    transition: all 0.3s;
}
.section-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #cbd5e1;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.paper-content {
    font-size: 1.15rem;
    line-height: 2; /* 适中的行距 */
    color: var(--text-main);
    text-align: left; /* 关键修改：左对齐，解决间距过大问题 */
}

/* 核心：填空槽位 (Slot) */
.slot {
    display: inline-block;
    min-width: 60px;
    padding: 0 4px;
    margin: 0 2px;
    border-bottom: 2px solid var(--slot-border);
    color: var(--slot-text);
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px 4px 0 0;
    background: var(--slot-bg);
    /* 防止槽位内部文字换行破坏布局 */
    /* white-space: nowrap;  如果内容太长可以允许换行，暂时保留默认 */
}
.slot:hover { background: var(--slot-hover-bg); color: var(--primary-dark); }
.slot.active {
    background: var(--slot-active-bg);
    color: var(--slot-active-text);
    border-bottom-color: transparent;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}
.slot:empty::after { content: "点击填词"; font-size: 0.8rem; opacity: 0.6; font-weight: normal; }

/* 阅读模式样式重置 */
body.mode-read .slot {
    background: transparent;
    color: inherit;
    border: none;
    border-bottom: 1px solid transparent;
    padding: 0; margin: 0;
    cursor: text;
    font-weight: normal;
}
body.mode-read .slot:empty { display: none; }
body.mode-read .section-label { display: none; } /* 阅读模式隐藏段落标签 */
body.mode-read .paper-section { margin-bottom: 20px; }

/* 翻译区域 */
.trans-box {
    margin-top: 12px;
    padding: 12px 16px;
    background: #f0fdf4;
    border-left: 3px solid #10b981;
    color: #15803d;
    font-size: 0.95rem;
    line-height: 1.6;
    border-radius: 0 6px 6px 0;
    display: block;
}
/* 动态翻译高亮 */
.trans-hl { font-weight: 700; color: #047857; margin: 0 2px; border-bottom: 1px dashed #86efac; }

/* =========================================
   6. 右侧：真题库 (Real Exams)
   ========================================= */
.exam-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
}
.exam-tag {
    font-size: 0.8rem;
    padding: 4px 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    cursor: pointer;
    color: var(--text-sub);
    transition: all 0.2s;
}
.exam-tag:hover { border-color: var(--primary); color: var(--primary); }
.exam-tag.active { background: var(--primary); color: white; border-color: var(--primary); font-weight: 600; }

.exam-para {
    margin-bottom: 20px;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
    transition: background 0.3s;
}
.exam-para.reading { background: #fffbeb; border-color: #fcd34d; } /* 正在朗读的高亮 */

.exam-en { font-size: 1rem; line-height: 1.8; color: var(--text-main); margin-bottom: 8px; }
.exam-cn { font-size: 0.9rem; color: var(--text-sub); line-height: 1.6; padding-top: 8px; border-top: 1px dashed #e2e8f0; display: none; }
.exam-cn.show { display: block; }

/* 真题中的模板句高亮 */
.tpl-hl {
    background-color: rgba(253, 224, 71, 0.2);
    border-bottom: 2px solid #fde047;
    cursor: help;
}

/* 单词弹窗 */
.word-popup {
    position: fixed;
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
    padding: 16px;
    border-radius: 12px;
    z-index: 1000;
    display: none;
    min-width: 220px;
    max-width: 300px;
    pointer-events: none;
}
.wp-word { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.wp-mean { font-size: 0.95rem; color: var(--text-main); margin-top: 4px; line-height: 1.4; }
.wp-source { font-size: 0.75rem; color: #94a3b8; margin-top: 8px; text-align: right; }

/* =========================================
   7. 底部状态与朗读条
   ========================================= */
#toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.8); color: white; padding: 10px 20px; border-radius: 20px;
    font-size: 0.9rem; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 200;
}

.audio-controls { display: flex; gap: 5px; }
.btn-icon { padding: 4px 8px; font-size: 0.8rem; border-radius: 4px; cursor: pointer; border: 1px solid #e2e8f0; background: white; }
.btn-icon:hover { color: var(--primary); border-color: var(--primary); }

@media (max-width: 1200px) {
    main { grid-template-columns: 280px 1fr; }
    .panel:nth-child(3) { display: none; } /* 小屏隐藏真题 */
}