/* --- 全局动态主题变量 --- */
:root {
  --bg-color: #f2f7f4; 
  --panel-bg: #f7faf8;
  --text-color: #2c3e35;
  --border-color: #dbe6df;
  --toolbar-bg: #1e2b24; 
}
[data-theme="default"] {
  --bg-color: #f4f4f6;
  --panel-bg: #fff;
  --text-color: #333;
  --border-color: #e0e0e0;
  --toolbar-bg: #1a1a1a;
}
[data-theme="eye-care"] {
  --bg-color: #ece6d5; 
  --panel-bg: #f4edd9;
  --text-color: #3c2e1e;
  --border-color: #e0d5ba;
}
[data-theme="dark"] {
  --bg-color: #121212;
  --panel-bg: #1e1e1e;
  --text-color: #cecece;
  --border-color: #333;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  transition: background 0.3s;
  overflow: hidden; 
}

.version-control-bar {
  background: #2c3e50;
  color: white;
  padding: 8px 20px;
  display: flex;
  gap: 15px;
  align-items: center;
  font-size: 13px;
  border-bottom: 1px solid #34495e;
  z-index: 101;
  position: relative;
}
.version-control-bar select, .version-control-bar button {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #34495e;
  background: #34495e;
  color: white;
}
.version-control-bar button { background: #27ae60; cursor: pointer; }
.version-control-bar button:hover { background: #2ecc71; }

.toolbar {
  height: 50px;
  padding: 0 20px;
  background: var(--toolbar-bg);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.controls-group { display: flex; align-items: center; gap: 12px; }
.btn {
  background: rgba(255,255,255,0.15); color: #fff; padding: 6px 14px; border-radius: 4px;
  cursor: pointer; border: 1px solid rgba(255,255,255,0.1); font-size: 14px; user-select: none;
}
.btn:hover { background: rgba(255,255,255,0.25); }
#fileInput { display: none; }

.main-layout { display: flex; width: 100vw; height: calc(100vh - 90px); position: relative; }
.sidebar {
  width: 0; height: 100%; background: var(--panel-bg);
  border-right: 0 solid var(--border-color); box-shadow: 2px 0 10px rgba(0,0,0,0.05);
  z-index: 95; transition: width 0.3s ease, border-width 0.1s;
  display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
}
.sidebar.open { width: 320px; border-right-width: 1px; }
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.tab { flex: 1; padding: 12px; text-align: center; cursor: pointer; background: rgba(0,0,0,0.02); font-size: 14px; }
.tab.active { background: var(--panel-bg); font-weight: bold; border-bottom: 2px solid #2e7d32; }
.sidebar-content { flex: 1; overflow-y: auto; padding: 10px; }
.toc-item, .bookmark-item {
  padding: 10px; border-radius: 4px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--border-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-item:hover, .bookmark-item:hover { background: rgba(0,0,0,0.05); }

.sidebar-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.15); z-index: 90; display: none;
  opacity: 0; transition: opacity 0.3s ease;
}
.sidebar-overlay.show { display: block; opacity: 1; }

.bookshelf-view { width: 100%; max-width: 1200px; margin: 20px auto; padding: 0 20px; overflow-y: auto; height: calc(100% - 40px); box-sizing: border-box; }
.bookshelf-title { font-size: 24px; font-weight: bold; margin-bottom: 20px; border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 25px; width: 100%; }
.book-card {
  background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px;
  padding: 20px; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.02);
  transition: transform 0.2s, box-shadow 0.2s; min-height: 140px; display: flex; flex-direction: column; justify-content: space-between; position: relative;
}
.book-card:hover { transform: translateY(-5px); box-shadow: 0 8px 15px rgba(0,0,0,0.06); }
.book-card .title { font-weight: bold; font-size: 16px; line-height: 1.4; word-break: break-all; }

.reader-view { display: none; flex: 1; height: 100%; position: relative; overflow: hidden; }
#viewer-container { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; position: relative; }
#viewer { width: 95%; height: 95%; max-width: 1200px; background: var(--panel-bg); box-shadow: 0 4px 20px rgba(0,0,0,0.08); border-radius: 8px; overflow: hidden; position: relative; }

.click-zone {
  position: absolute; top: 0; bottom: 0; width: 35%; z-index: 85; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 36px; color: rgba(255,255,255,0);
  user-select: none; transition: background 0.2s, color 0.2s;
}
.click-zone:hover { background: rgba(0,0,0,0.01); color: rgba(128,128,128,0.1); }
#leftZone { left: 0; justify-content: flex-start; padding-left: 20px; }
#rightZone { right: 0; justify-content: flex-end; padding-right: 20px; }

#loadingTip { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 16px; color: #888; z-index: 81; display: none; }

/* AI 悬浮窗样式 */
.ai-chat-trigger {
  position: fixed; bottom: 30px; right: 30px; width: 50px; height: 50px;
  background: #27ae60; color: white; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 24px; cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2); z-index: 1000;
}
.ai-chat-window {
  position: fixed; bottom: 90px; right: 30px; width: 300px; height: 400px;
  background: white; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  display: none; flex-direction: column; z-index: 1000; overflow: hidden;
}
.chat-header { padding: 10px; background: #2c3e50; color: white; display: flex; justify-content: space-between; }
.chat-messages { 
  flex: 1; 
  padding: 10px; 
  overflow-y: auto; 
  font-size: 13px; 
  color: #333;
  
  /* 关键点：添加这两行 */
  white-space: pre-wrap;   /* 让 \n 换行符生效，并自动处理长文本折行 */
  word-wrap: break-word;   /* 确保超长单词或连续字符不会撑破窗口 */
}
.chat-input-area { display: flex; padding: 10px; border-top: 1px solid #eee; }