/* ========== 基础重置 ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { border: none; cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ========== 导航栏 ========== */
#navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid #eee;
  font-size: 16px;
}

#nav-back {
  color: #4a90d9;
  cursor: pointer;
  min-width: 60px;
  font-size: 14px;
}

#nav-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#nav-right {
  min-width: 60px;
  text-align: right;
}

/* ========== 页面容器 ========== */
#page-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* ========== 书架页 ========== */
/* 添加书籍区域 */
.add-book-area {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
}

.add-book-area input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.add-book-area input:focus {
  border-color: #4a90d9;
}

.add-book-area button {
  padding: 10px 20px;
  background: #4a90d9;
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}

.add-book-area button:disabled {
  background: #ccc;
}

/* 书架网格 */
.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.book-card {
  position: relative;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.book-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.book-card .cover-placeholder {
  width: 100%;
  aspect-ratio: 3/4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 1px solid #d4c5a9;
  background: #f8f3e8;
  color: #5a4632;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
}

/* 空书架 */
.empty-shelf {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  font-size: 14px;
}

/* 加载提示 */
.loading {
  text-align: center;
  padding: 40px;
  color: #999;
}

/* ========== 章节列表页 ========== */
.chapter-list {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

.chapter-item {
  display: block;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 15px;
  color: #333;
  transition: background 0.15s;
}

.chapter-item:active {
  background: #f5f5f5;
}

.chapter-item:last-child {
  border-bottom: none;
}

/* 分页控件 */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
}

.pagination button {
  padding: 8px 16px;
  background: #4a90d9;
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
}

.pagination button:disabled {
  background: #ccc;
  cursor: default;
}

.pagination .page-info {
  font-size: 14px;
  color: #666;
}

/* ========== 阅读器页 ========== */
.reader {
  background: #fafafa;
  min-height: calc(100vh - 48px);
  padding-bottom: 80px;
}

.reader .chapter-title {
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  padding: 24px 0 16px;
  color: #333;
}

.reader .content {
  font-size: 18px;
  line-height: 2;
  color: #333;
  padding: 0 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* 阅读器工具栏 */
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 48px;
  z-index: 99;
}

.reader-toolbar button {
  padding: 6px 14px;
  background: #f0f0f0;
  border-radius: 4px;
  font-size: 14px;
  color: #333;
}

.reader-toolbar button:active {
  background: #e0e0e0;
}

.reader-toolbar .font-size-label {
  font-size: 13px;
  color: #999;
}

/* 阅读器底部导航 */
.reader-nav {
  display: flex;
  justify-content: space-between;
  padding: 24px 0;
  gap: 12px;
}

.reader-nav button {
  flex: 1;
  padding: 12px 0;
  background: #4a90d9;
  color: #fff;
  border-radius: 6px;
  font-size: 15px;
  text-align: center;
}

.reader-nav button:disabled {
  background: #ddd;
  color: #999;
  cursor: default;
}

/* ========== 目录弹窗 ========== */
.toc-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}

.toc-overlay.show {
  display: block;
}

.toc-panel {
  position: fixed;
  top: 0; right: 0;
  width: 85%;
  max-width: 360px;
  height: 100%;
  background: #fff;
  overflow-y: auto;
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.toc-overlay.show .toc-panel {
  transform: translateX(0);
}

.toc-panel .toc-header {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 16px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  font-size: 16px;
  z-index: 1;
}

.toc-panel .toc-item {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid #f5f5f5;
  font-size: 14px;
  color: #333;
}

.toc-panel .toc-item:active {
  background: #f0f0f0;
}

.toc-panel .toc-item.current {
  color: #4a90d9;
  font-weight: 600;
}

/* 继续阅读提示条 */
.continue-banner {
  background: #e8f4fd;
  color: #4a90d9;
  padding: 14px 16px;
  text-align: center;
  font-size: 15px;
  cursor: pointer;
  border-bottom: 1px solid #d0e8f7;
  font-weight: 500;
}
.continue-banner:hover {
  background: #d8effb;
}
.continue-banner:active {
  background: #c8e6f9;
}

/* 书架进度标记 */
.continue-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 1;
  background: #4a90d9;
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.6;
  cursor: pointer;
}
.continue-badge:hover {
  background: #3a7bc8;
}

/* ========== 消息提示 ========== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 300;
  display: none;
}

.toast.show {
  display: block;
}

/* ========== 响应式调整 ========== */
@media (min-width: 768px) {
  #page-content {
    padding: 24px;
  }
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  .reader .content {
    font-size: 20px;
    padding: 0 20px;
  }
}

/* ========== 登录/注册页 ========== */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 48px);
  padding: 20px;
}
.login-form {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 12px;
  padding: 32px 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.login-form h2 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 22px;
  color: #333;
}
.login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 15px;
  margin-bottom: 16px;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}
.login-form input:focus {
  border-color: #4a90d9;
}
.login-form button {
  width: 100%;
  padding: 10px;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
}
.login-form button:disabled {
  background: #aaa;
  cursor: not-allowed;
}
.login-form .auth-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: #4a90d9;
  cursor: pointer;
  font-size: 14px;
}
.login-form .auth-link:hover {
  text-decoration: underline;
}
.login-form .error {
  color: #e74c3c;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* ========== 书架管理按钮 ========== */
.shelf-action-btn {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  border: none;
  cursor: pointer;
  margin-top: 6px;
}
.shelf-action-btn.add {
  background: #4a90d9;
  color: #fff;
}
.shelf-action-btn.add:disabled {
  background: #ddd;
  color: #999;
  cursor: not-allowed;
}
.shelf-action-btn.remove {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  background: rgba(245,245,245,0.9);
  color: #999;
  border: 1px solid #eee;
}
.shelf-action-btn.remove:hover {
  background: #fee;
  color: #e74c3c;
  border-color: #fcc;
}

/* 全局书架链接 */
.global-shelf-link {
  text-align: center;
  margin-top: 20px;
  color: #4a90d9;
  cursor: pointer;
  font-size: 14px;
}

/* 导航栏右侧 */
#nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
#nav-username {
  color: #666;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#nav-logout {
  padding: 3px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #f9f9f9;
  color: #666;
  cursor: pointer;
  font-size: 12px;
}
#nav-logout:hover {
  background: #fee;
  color: #e74c3c;
  border-color: #fcc;
}
