/* ===== 基础重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f5f5f5; color: #333; line-height: 1.6;
}
button { border: none; background: none; cursor: pointer; font: inherit; color: inherit; }
ul { list-style: none; }
input { border: none; outline: none; font: inherit; }

/* ===== 颜色变量 ===== */
:root {
  --primary: #8B4513;
  --primary-light: #D2691E;
  --bg: #f5f5f5;
  --card-bg: #fff;
  --text: #333;
  --text-secondary: #666;
  --border: #e0e0e0;
  --success: #4CAF50;
  --warning: #FF9800;
  --error: #f44336;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 12px;
}

/* 深色模式 */
body.dark {
  --bg: #1a1a1a; --card-bg: #2d2d2d; --text: #e0e0e0;
  --text-secondary: #aaa; --border: #444;
}

/* ===== 布局 ===== */
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); position: relative; }
@media (min-width: 768px) { #app { max-width: 768px; } }

/* 头部 */
.header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 100; }
.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 1.5rem; }
.site-title { font-size: 1.1rem; font-weight: 600; }
.icon-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 1.2rem; transition: background 0.2s; }
.icon-btn:hover { background: rgba(255,255,255,0.15); }

/* 底部导航 */
.bottom-nav { display: flex; background: var(--card-bg); border-top: 1px solid var(--border); padding: 8px 0; position: sticky; bottom: 0; z-index: 100; }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; color: var(--text-secondary); transition: color 0.2s; }
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 1.3rem; }
.nav-label { font-size: 0.7rem; }

/* 主内容区 */
.main-content { flex: 1; padding: 16px; padding-bottom: 80px; }
.page { display: none; }
.page.active { display: block; }

/* ===== 卡片 ===== */
.card { background: var(--card-bg); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 8px; color: var(--primary); }
.card-content { color: var(--text-secondary); font-size: 0.9rem; }

/* ===== 首页 ===== */
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-item { flex: 1; background: var(--card-bg); border-radius: var(--radius); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); }
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.quick-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px; background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 0.75rem; color: var(--text-secondary); }
.quick-btn span:first-child { font-size: 1.5rem; }
.section-title { font-size: 1rem; font-weight: 600; margin: 16px 0 8px; color: var(--text); }

/* 文章卡片 */
.article-card { background: var(--card-bg); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.15s; }
.article-card:active { transform: scale(0.98); }
.article-card-title { font-weight: 600; margin-bottom: 4px; }
.article-card-meta { font-size: 0.75rem; color: var(--text-secondary); display: flex; gap: 8px; flex-wrap: wrap; }
.tag { background: var(--primary); color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; }

/* ===== 全部文章页 ===== */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-btn { padding: 6px 14px; border-radius: 16px; font-size: 0.8rem; background: var(--card-bg); color: var(--text-secondary); border: 1px solid var(--border); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 详情弹层 ===== */
.detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: none; align-items: flex-end; }
.detail-overlay.open { display: flex; }
.detail-panel { background: var(--card-bg); width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; overflow-y: auto; padding: 20px; }
.detail-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(0,0,0,0.1); font-size: 1.1rem; }
.detail-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; padding-right: 40px; }
.detail-meta { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.detail-section { margin-bottom: 16px; }
.detail-section h3 { font-size: 0.95rem; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.detail-section p, .detail-section li { font-size: 0.9rem; margin-bottom: 4px; }
.detail-section ul { padding-left: 16px; list-style: disc; }
.original-text { background: #FFF8E1; padding: 12px; border-radius: 8px; margin-bottom: 8px; font-size: 0.9rem; line-height: 1.8; }
body.dark .original-text { background: #3d3520; }

/* ===== 引导学习 ===== */
.guide-steps { display: flex; gap: 8px; margin-bottom: 16px; }
.step-btn { flex: 1; padding: 10px 4px; text-align: center; border-radius: 8px; font-size: 0.8rem; background: var(--card-bg); border: 1px solid var(--border); color: var(--text-secondary); }
.step-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.guide-content { background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.guide-content h3 { color: var(--primary); margin-bottom: 10px; }
.guide-content p { margin-bottom: 8px; font-size: 0.9rem; }

/* ===== 答题 ===== */
.quiz-options { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.quiz-option { padding: 12px 16px; border-radius: 8px; border: 2px solid var(--border); background: var(--card-bg); text-align: left; font-size: 0.9rem; transition: all 0.2s; }
.quiz-option:hover { border-color: var(--primary); }
.quiz-option.correct { border-color: var(--success); background: #E8F5E9; }
.quiz-option.wrong { border-color: var(--error); background: #FFEBEE; }
.quiz-option.disabled { pointer-events: none; }
.quiz-feedback { margin-top: 12px; padding: 10px; border-radius: 8px; font-size: 0.85rem; }
.quiz-feedback.correct { background: #E8F5E9; color: var(--success); }
.quiz-feedback.wrong { background: #FFEBEE; color: var(--error); }
.quiz-type-btns { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.quiz-type-btn { padding: 8px 16px; border-radius: 16px; font-size: 0.8rem; background: var(--card-bg); border: 1px solid var(--border); color: var(--text-secondary); }
.quiz-type-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 游戏 ===== */
.game-score { text-align: center; font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; }
.game-card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.game-question { font-size: 1rem; margin-bottom: 16px; text-align: center; }
.game-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-option { padding: 14px; border-radius: 8px; border: 2px solid var(--border); background: var(--card-bg); font-size: 0.9rem; }
.game-option:hover { border-color: var(--primary); }
.game-option.correct { border-color: var(--success); background: #E8F5E9; }
.game-option.wrong { border-color: var(--error); background: #FFEBEE; }
.game-option.disabled { pointer-events: none; }

/* ===== 统计 ===== */
.progress-ring { width: 120px; height: 120px; margin: 0 auto 16px; }
.heatmap { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; margin-top: 8px; }
.heatmap-cell { width: 100%; aspect-ratio: 1; border-radius: 2px; background: var(--border); }
.heatmap-cell.level-1 { background: #C8E6C9; }
.heatmap-cell.level-2 { background: #81C784; }
.heatmap-cell.level-3 { background: #4CAF50; }
.heatmap-cell.level-4 { background: #2E7D32; }

/* ===== 设置 ===== */
.setting-item { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-item:last-child { border-bottom: none; }
.setting-label { font-size: 0.9rem; }
.setting-control { display: flex; align-items: center; gap: 8px; }
.font-slider { width: 120px; -webkit-appearance: none; height: 4px; border-radius: 2px; background: var(--border); outline: none; }
.font-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); cursor: pointer; }
.toggle-switch { position: relative; width: 44px; height: 24px; background: var(--border); border-radius: 12px; cursor: pointer; transition: background 0.3s; }
.toggle-switch.on { background: var(--primary); }
.toggle-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.3s; }
.toggle-switch.on::after { transform: translateX(20px); }

/* ===== 侧边菜单 ===== */
.side-menu { position: fixed; inset: 0; z-index: 300; display: none; }
.side-menu.open { display: block; }
.menu-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.menu-panel { position: absolute; top: 0; left: 0; width: 240px; height: 100%; background: var(--card-bg); padding: 20px 0; }
.menu-header { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 16px; border-bottom: 1px solid var(--border); }
.menu-list { padding: 8px 0; }
.menu-item { padding: 14px 20px; font-size: 0.95rem; cursor: pointer; transition: background 0.15s; }
.menu-item:hover, .menu-item.active { background: rgba(139,69,19,0.1); color: var(--primary); }

/* ===== 搜索 ===== */
.search-panel { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; background: var(--card-bg); z-index: 250; display: none; flex-direction: column; max-height: 60vh; border-radius: 0 0 16px 16px; box-shadow: var(--shadow); }
@media (min-width: 768px) { .search-panel { max-width: 768px; } }
.search-panel.open { display: flex; }
.search-box { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
#search-input { flex: 1; font-size: 1rem; padding: 8px; background: var(--bg); border-radius: 8px; }
.search-results { overflow-y: auto; padding: 8px; }
.search-result-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.search-result-item:hover { background: var(--bg); }
.search-result-item h4 { font-size: 0.9rem; margin-bottom: 2px; }
.search-result-item p { font-size: 0.75rem; color: var(--text-secondary); }

/* ===== 动画 ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.3s ease; }

/* ===== 收藏按钮 ===== */
.fav-btn { font-size: 1.2rem; padding: 4px 8px; border-radius: 6px; }
.fav-btn.active { color: #FFD700; }