/* 基础重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  line-height: 1.8;
  color: #333;
  background-color: #f7f3ed;
  min-height: 100vh;
  overflow-x: hidden;
}

/* 主题：护眼（默认） */
body.theme-sepia {
  background-color: #f4ecd8;
  color: #5b4636;
}

body.theme-sepia .header,
body.theme-sepia .footer,
body.theme-sepia .chapter-nav {
  background-color: #ede4cb;
  border-color: #d9cba8;
}

body.theme-sepia .sidebar,
body.theme-sepia .settings-panel {
  background-color: #f4ecd8;
  color: #5b4636;
}

body.theme-sepia .sidebar-header,
body.theme-sepia .settings-header {
  border-color: #d9cba8;
}

body.theme-sepia .toc-item {
  border-color: #e8dcc0;
}

body.theme-sepia .toc-item.active {
  background-color: #ede4cb;
  color: #8b6914;
}

body.theme-sepia .setting-item {
  border-color: #e8dcc0;
}

body.theme-sepia .ctrl-btn,
body.theme-sepia .page-btn,
body.theme-sepia .chapter-nav-btn {
  background-color: #ede4cb;
  color: #5b4636;
}

body.theme-sepia .icon-btn {
  color: #5b4636;
}

/* 主题：浅色 */
body.theme-light {
  background-color: #ffffff;
  color: #333333;
}

body.theme-light .header,
body.theme-light .footer,
body.theme-light .chapter-nav {
  background-color: #f5f5f5;
  border-color: #e0e0e0;
}

body.theme-light .sidebar,
body.theme-light .settings-panel {
  background-color: #ffffff;
  color: #333333;
}

body.theme-light .sidebar-header,
body.theme-light .settings-header {
  border-color: #e0e0e0;
}

body.theme-light .toc-item {
  border-color: #f0f0f0;
}

body.theme-light .toc-item.active {
  background-color: #f0f7ff;
  color: #1a73e8;
}

body.theme-light .setting-item {
  border-color: #f0f0f0;
}

body.theme-light .ctrl-btn,
body.theme-light .page-btn,
body.theme-light .chapter-nav-btn {
  background-color: #f5f5f5;
  color: #333333;
}

body.theme-light .icon-btn {
  color: #333333;
}

/* 主题：夜间 */
body.theme-dark {
  background-color: #1a1a1a;
  color: #b8b8b8;
}

body.theme-dark .header,
body.theme-dark .footer,
body.theme-dark .chapter-nav {
  background-color: #222222;
  border-color: #333333;
}

body.theme-dark .sidebar,
body.theme-dark .settings-panel {
  background-color: #1a1a1a;
  color: #b8b8b8;
}

body.theme-dark .sidebar-header,
body.theme-dark .settings-header {
  border-color: #333333;
}

body.theme-dark .toc-item {
  border-color: #2a2a2a;
}

body.theme-dark .toc-item.active {
  background-color: #2a2a2a;
  color: #6ab7ff;
}

body.theme-dark .setting-item {
  border-color: #2a2a2a;
}

body.theme-dark .ctrl-btn,
body.theme-dark .page-btn,
body.theme-dark .chapter-nav-btn {
  background-color: #2a2a2a;
  color: #b8b8b8;
}

body.theme-dark .icon-btn {
  color: #b8b8b8;
}

body.theme-dark .content h2 {
  color: #d0d0d0;
}

/* 顶部导航 */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background-color: #ede4cb;
  border-bottom: 1px solid #d9cba8;
  z-index: 100;
}

.title {
  font-size: 17px;
  font-weight: 500;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #5b4636;
  cursor: pointer;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.icon-btn:active {
  background-color: rgba(0, 0, 0, 0.1);
}

/* 侧边栏目录 */
.sidebar {
  position: fixed;
  top: 0;
  left: -80%;
  width: 80%;
  max-width: 320px;
  height: 100%;
  background-color: #f7f3ed;
  z-index: 200;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e8dcc0;
  height: 48px;
}

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 500;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.toc-item {
  display: block;
  padding: 12px 16px;
  font-size: 15px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid #f0e6d0;
  transition: background-color 0.2s;
}

.toc-item:active {
  background-color: rgba(0, 0, 0, 0.05);
}

.toc-item.active {
  background-color: #ede4cb;
  font-weight: 500;
}

/* 遮罩层 */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

/* 设置面板 */
.settings-panel {
  position: fixed;
  top: 48px;
  right: -100%;
  width: 100%;
  max-width: 400px;
  height: calc(100% - 48px);
  background-color: #f7f3ed;
  z-index: 150;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.settings-panel.open {
  right: 0;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e8dcc0;
}

.settings-header h2 {
  font-size: 17px;
  font-weight: 500;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.setting-item {
  padding: 16px 0;
  border-bottom: 1px solid #f0e6d0;
}

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

.setting-item label {
  display: block;
  font-size: 15px;
  margin-bottom: 12px;
  font-weight: 500;
}

.setting-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.ctrl-btn {
  width: 44px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background-color: #ede4cb;
  color: #5b4636;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:active {
  opacity: 0.7;
}

#fontSizeValue,
#pageSizeValue {
  font-size: 15px;
  min-width: 50px;
  text-align: center;
}

.theme-options {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.theme-btn {
  flex: 1;
  max-width: 100px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.theme-btn.active {
  border-color: #1a73e8;
}

/* 阅读内容区 */
.reader {
  padding: 60px 16px 120px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
}

.content {
  font-size: 1rem;
  line-height: 1.9;
  text-align: justify;
}

.content h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 24px 0 16px;
  text-align: center;
  line-height: 1.5;
}

.content p {
  margin-bottom: 1em;
  text-indent: 2em;
}

.content .no-indent {
  text-indent: 0;
}

/* 底部分页控制 */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background-color: #ede4cb;
  border-top: 1px solid #d9cba8;
  z-index: 100;
}

.page-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background-color: #e0d5b8;
  color: #5b4636;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-btn:active:not(:disabled) {
  opacity: 0.7;
}

.page-info {
  font-size: 14px;
  color: inherit;
}

/* 章节上下章导航 */
.chapter-nav {
  position: fixed;
  bottom: 52px;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background-color: #f0e6d0;
  border-top: 1px solid #e0d5b8;
  z-index: 99;
}

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background-color: #e8dcc0;
  color: #5b4636;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chapter-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chapter-nav-btn:active:not(:disabled) {
  opacity: 0.7;
}

/* 平板适配 */
@media (min-width: 768px) {
  .reader {
    padding: 70px 24px 130px;
  }

  .content {
    font-size: 1.05rem;
    line-height: 2;
  }

  .content h2 {
    font-size: 24px;
  }

  .sidebar {
    width: 320px;
    left: -320px;
  }

  .header {
    height: 56px;
  }

  .footer {
    height: 60px;
  }

  .chapter-nav {
    bottom: 60px;
  }

  .reader {
    padding-top: 70px;
    padding-bottom: 140px;
  }
}

/* 桌面端适配 */
@media (min-width: 1024px) {
  .reader {
    padding: 80px 32px 150px;
  }

  .content {
    font-size: 1.1rem;
  }
}
