/* ========== 本地字体声明 ========== */
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/patrick-hand-latin-400-normal.woff2') format('woff2'),
       url('/static/fonts/patrick-hand-latin-400-normal.woff') format('woff');
}

/* ========== 全局样式 ========== */
* {
    box-sizing: border-box;
}

body { 
    font-family: "KaiTi", "STKaiti", sans-serif; 
    background-color: #f4f4f4; 
    padding: 10px; 
    margin: 0; 
    overflow-x: hidden;
    width: 100%;
}

/* 主布局：垂直排列 */
.main-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* 第一行：左右并排 - 高度一致 */
.top-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: stretch;
    width: 100%;
}

/* 左侧教材库 - 修复手机溢出 */
.left-sidebar {
    flex: 1 1 320px;
    min-width: 0;
    width: 100%;
    background: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    max-height: 70vh;
}

/* 右侧输入面板 - 修复手机溢出 */
.right-input-panel {
    flex: 2 1 350px;
    min-width: 0;
    width: 100%;
    display: flex;
}

#inputPanel { 
    text-align: center; 
    padding: 20px; 
    background: white;
    border-radius: 20px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow-x: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #1e466e;
}

.sidebar-tip {
    font-size: 11px;
    color: #8ba0b0;
    margin-bottom: 12px;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

#inputPanel h2 {
    margin-top: 0;
    margin-bottom: 8px;
    color: #1e466e;
    font-size: 1.3rem;
    word-break: break-word;
}

#inputPanel p {
    color: #6c757d;
    font-size: 13px;
    margin-bottom: 16px;
    word-break: break-word;
}

#textInput { 
    width: 100%;
    max-width: 100%;
    height: 120px; 
    font-size: 18px; 
    padding: 10px; 
    margin-bottom: 10px; 
    border-radius: 12px;
    border: 1px solid #ccc;
    font-family: "KaiTi", monospace;
    resize: vertical;
    flex: 1;
}

.input-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

#startBtn, #clearBtn { 
    padding: 10px 24px; 
    font-size: 16px; 
    background-color: #007bff; 
    color: white; 
    border: none; 
    border-radius: 30px; 
    cursor: pointer; 
    transition: background-color 0.2s;
}

#startBtn:hover, #clearBtn:hover { 
    background-color: #0056b3; 
}

/* 第二行：写字区域 */
.bottom-row {
    width: 100%;
    background: white;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    overflow-x: auto;
}

#toolbar { 
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 16px;
}

#backBtn { 
    padding: 8px 20px; 
    font-size: 14px; 
    background-color: #6c757d; 
    color: white; 
    border: none; 
    border-radius: 30px; 
    cursor: pointer; 
}

#backBtn:hover {
    background-color: #5a6268;
}

/* 写字区域容器 */
.hanzi-container { 
    display: flex; 
    justify-content: flex-start; 
    flex-wrap: wrap; 
    gap: 15px; 
    padding: 10px; 
    background: #f9f9f9;
    border-radius: 20px;
    min-height: 350px;
}

.char-item { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.info-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    width: 100%; 
    margin-bottom: 5px; 
}

.pinyin-text { 
    font-family: 'Patrick Hand', 'KaiTi', 'STKaiti', 'Microsoft YaHei', sans-serif; 
    color: #007bff; 
    font-weight: bold; 
    font-size: 16px; 
}

.stroke-badge { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    width: 20px; 
    height: 20px; 
    border-radius: 50%; 
    background-color: #007bff; 
    color: white; 
    font-size: 11px; 
    font-weight: bold; 
}

.character-box { 
    width: 60px; 
    height: 60px; 
    border: 1px solid #ddd; 
    border-radius: 6px; 
    background: white; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); 
    position: relative; 
}

.character-box svg { 
    position: absolute; 
    top: 50%;  /* 改为相对居中 */
    left: 50%; /* 改为相对居中 */
    transform: translate(-62%, -60%); /* 使用transform实现完美居中 */
    width: 80px;  /* 稍微缩小，让笔画更完整显示 */
    height: 80px; /* 稍微缩小 */
}

.punctuation-text { 
    font-family: "SimSun", serif; 
    font-size: 36px; 
    font-weight: bold; 
    color: #333; 
    margin: 0 5px; 
    display: inline-flex; 
    align-items: center; 
    margin-top: 20px; 
}

/* ========== 教材折叠区域样式 ========== */
.tree-container {
    font-size: 13px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(70vh - 80px);
    min-height: 320px;
}

/* 教材级折叠项 */
.textbook-group {
    margin-bottom: 16px;
    border: 1px solid #e0ecf9;
    border-radius: 14px;
    overflow: hidden;
    background: white;
    width: 100%;
}

.textbook-header {
    background: linear-gradient(135deg, #e8f0fe 0%, #dce8f5 100%);
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 15px;
    color: #1e466e;
    transition: background 0.2s;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.textbook-header:hover {
    background: linear-gradient(135deg, #dce8f5 0%, #d0e0f0 100%);
}

.textbook-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.textbook-stats {
    display: flex;
    gap: 8px;
    font-size: 10px;
    font-weight: normal;
    color: #2c7da0;
    background: rgba(255,255,255,0.6);
    padding: 3px 8px;
    border-radius: 30px;
    flex-wrap: wrap;
}

.textbook-stats .stat-item {
    white-space: nowrap;
}

.textbook-arrow {
    font-size: 12px;
    color: #5a7d9a;
    flex-shrink: 0;
}

/* 教材内容 - 默认折叠 */
.textbook-content {
    display: none;
    padding: 12px;
    background: #fefefe;
    width: 100%;
    overflow-x: hidden;
}

.textbook-content.open {
    display: block;
}

/* 单元级样式 */
.unit-group {
    margin-bottom: 12px;
    border: 1px solid #eef2f8;
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
}

.unit-title {
    font-weight: bold;
    font-size: 13px;
    padding: 10px 14px;
    background: #f5f8fc;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #2c5a8c;
    transition: background 0.2s;
    position: sticky;
    top: 0;
    background: #f5f8fc;
    z-index: 4;
}

.unit-title:hover {
    background: #eef3fc;
}

.unit-arrow {
    font-size: 11px;
    color: #6c8eae;
}

/* 单元内容 - 默认折叠 */
.unit-content {
    display: none;
    padding: 8px 12px;
    background: white;
}

.unit-content.open {
    display: block;
}

.lesson-card {
    border: 1px solid #e9ecef;
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: hidden;
}

/* 修改后 —— 加上粘性定位 */
.lesson-header {
    background: #f8f9fa;
    padding: 8px 12px;
    cursor: pointer;
    position: sticky;
    top: 0;           /* 吸顶 */
    z-index: 20;      /* 确保在内容上方 */
    border-bottom: 1px solid #e0e0e0;
}

.lesson-header:hover {
    background: #eef2f6;
}

.lesson-title {
    font-size: 13px;
    color: #2c3e50;
    word-break: break-word;
}

.lesson-content {
    padding: 10px 12px;
    background: white;
    display: none;
    border-top: 1px solid #eee;
}

.lesson-content.open {
    display: block;
}

.data-section {
    margin-bottom: 12px;
    border-bottom: 1px dashed #e9ecef;
    padding-bottom: 10px;
}

.section-label {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 40px;        /* 比 .lesson-header 略低，避免重叠，可根据实际微调 */
    background: white;
    padding: 6px 0;
    z-index: 15;
}
.section-label .select-all-btn {
    background: #28a745;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 10px;
    cursor: pointer;
    white-space: nowrap;
}

/* 通用列表样式 */
.char-words-list, .vocabulary-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.char-word-item, .vocabulary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #fef9e6;
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

/* 词汇表特殊背景色 */
.vocabulary-item {
    background: #e8f5e9;
}

.char-word-char {
    font-weight: bold;
    font-size: 16px;
    color: #2c7a4d;
    margin-right: 10px;
}

.char-word-words, .vocabulary-word {
    color: #6c757d;
    font-size: 11px;
    word-break: break-word;
    flex: 1;
}

.select-char-btn, .select-vocab-btn {
    background: #007bff20;
    border: none;
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 11px;
    color: #007bff;
    cursor: pointer;
    white-space: nowrap;
}

.select-char-btn:hover, .select-vocab-btn:hover {
    background: #007bff;
    color: white;
}

.content-preview {
    background: #f1f8e9;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 11px;
    max-height: 100px;
    overflow-y: auto;
    word-break: break-word;
}

.content-select-btn {
    background: #17a2b8;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 10px;
    cursor: pointer;
    white-space: nowrap;
}

.loading, .error-msg {
    text-align: center;
    padding: 30px;
    color: #6c757d;
}

.error-msg {
    color: #dc3545;
}

.scroll-highlight {
    animation: highlightFlash 0.5s ease;
}

@keyframes highlightFlash {
    0% { box-shadow: 0 0 0 0 #007bff; }
    50% { box-shadow: 0 0 0 3px #007bff80; }
    100% { box-shadow: 0 0 0 0 #007bff; }
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #019eca;
    color: white;
    padding: 8px 16px;
    border-radius: 30px;
    z-index: 9999;
    font-size: 13px;
    animation: fadeOut 1.5s ease forwards;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

/* 移动端适配 - 修复手机溢出 */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }
    
    .main-layout {
        gap: 12px;
    }
    
    .top-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .left-sidebar {
        flex: auto;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        max-height: 50vh;
    }
    
    .right-input-panel {
        flex: auto;
        width: 100%;
        min-width: 0;
    }
    
    #inputPanel {
        padding: 16px;
    }
    
    #inputPanel h2 {
        font-size: 1.1rem;
    }
    
    #textInput {
        height: 100px;
        font-size: 16px;
    }
    
    #startBtn, #clearBtn {
        padding: 8px 18px;
        font-size: 14px;
    }
    
    .bottom-row {
        padding: 12px;
    }
    
    .textbook-stats {
        font-size: 9px;
        gap: 6px;
    }
    
    .textbook-title {
        font-size: 13px;
    }
    
    .textbook-header {
        padding: 10px 12px;
    }
    
    .tree-container {
        max-height: 40vh;
        min-height: 280px;
    }
    

    .punctuation-text {
        font-size: 30px;
        margin-top: 15px;
    }
    
    .pinyin-text {
        font-size: 14px;
    }
    
    .char-word-char {
        font-size: 15px;
    }
}


.toast-success {
    background: #28a745;
}

.toast-warning {
    background: #ffc107;
    color: #333;
}

.toast-error {
    background: #dc3545;
}


/* 读一读，记一记 样式 */
.recite-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.recite-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fef9e6;
    border-radius: 12px;
    border-left: 4px solid #ff9800;
    font-size: 14px;
}

.recite-content {
    color: #5d4037;
    line-height: 1.5;
}

.select-recite-btn {
    background: #ff9800;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.select-recite-btn:hover {
    background: #f57c00;
}