:root {
  --bg: #f7f3eb;
  --text: #2c2c2c;
  --card: #ffffff;
  --accent: #5b8c5a;
  --border: #e8e2d6;
  --radius: 12px;
  --font-size: 18px;
  --reader-font: "Microsoft YaHei", "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --text: #e0e0e0;
  --card: #252525;
  --border: #333;
  --accent: #7cb87c;
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --text: #5b4636;
  --card: #faf6eb;
  --border: #e0d6c2;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--reader-font);
  background: var(--bg);
  color: var(--text);
}

.view { height: 100%; width: 100%; }
.hidden { display: none !important; }

/* 登录 */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f7f3eb, #e8f0e8);
}
.login-card {
  background: var(--card);
  padding: 2.5rem;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  width: 90%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 2rem; margin-bottom: 0.3rem; letter-spacing: 2px; }
.subtitle { color: #888; margin-bottom: 2rem; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}
.login-card button {
  width: 100%;
  padding: 0.9rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
}
.error { color: #c44; margin-top: 1rem; font-size: 0.9rem; }

/* 书架 */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.6rem;
}
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.upload-btn, .ghost {
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
}
.upload-btn { background: var(--accent); color: white; border: none; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1.2rem;
  padding: 1.2rem;
  overflow-y: auto;
  height: calc(100% - 60px);
}
.book-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: transform 0.2s;
}
.book-card:hover { transform: translateY(-3px); }
.book-cover {
  height: 160px;
  background: linear-gradient(135deg, #d4e4d4, #a8c5a8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: #fff;
}
.book-info { padding: 0.7rem; }
.book-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author { font-size: 0.75rem; color: #888; margin-top: 0.2rem; }

/* 阅读器核心修复 */
#reader-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.4rem;
  flex-shrink: 0;
  z-index: 30;
}

.reader-toolbar button, .reader-toolbar select {
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.reader-toolbar button:hover, .reader-toolbar select:hover {
  background: var(--border);
}

.toolbar-center { display: flex; align-items: center; gap: 0.6rem; }
.toolbar-right { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

#font-select {
  max-width: 110px;
  background: var(--bg);
  border: 1px solid var(--border);
}

#viewer-container {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

#viewer {
  width: 100% !important;
  height: 100% !important;
  position: absolute;
  top: 0;
  left: 0;
}

#viewer iframe {
  border: none !important;
  width: 100% !important;
  height: 100% !important;
}

#loading-tip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #888;
  font-size: 1rem;
  z-index: 10;
  pointer-events: none;
}

.note-panel {
  position: absolute;
  right: 0;
  top: 48px;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  z-index: 40;
}

.note-panel textarea {
  width: 100%;
  height: 90px;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

#save-note-btn {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.55rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.note-item {
  margin-top: 0.8rem;
  padding: 0.7rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.88rem;
}

#upload-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0%;
  z-index: 9999;
  transition: width 0.2s;
  pointer-events: none;
}

/* 全屏时隐藏工具栏可选（需要的话取消注释） */
/* :fullscreen .reader-toolbar { display: none; } */