:root {
  --content-font-size: 18px;
  --content-line-height: 1.8;
  --content-font-family: serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .3s, color .3s;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body[data-theme="light"] {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #2c3e50;
  --reader-bg: #fafafa;
  --reader-text: #333;
  --border: #e0e4e8;
  --primary: #3498db;
  --primary-hover: #ffffff;
  --accent: #ecf0f1;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

body[data-theme="sepia"] {
  --bg: #f4ecd8;
  --card: #fff8e8;
  --text: #5b4636;
  --reader-bg: #f9f1e5;
  --reader-text: #5b4636;
  --border: #e0d5b7;
  --primary: #8b6f47;
  --primary-hover: #fff8e8;
  --accent: #eadfd0;
  --shadow: 0 2px 12px rgba(91,70,54,0.1);
}

body[data-theme="dark"] {
  --bg: #1e1e1e;
  --card: #2d2d2d;
  --text: #cccccc;
  --reader-bg: #181818;
  --reader-text: #b0b0b0;
  --border: #444;
  --primary: #4a7c59;
  --primary-hover: #2d2d2d;
  --accent: #3a3a3a;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.hidden {
  display: none !important;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
  white-space: nowrap;
}

.main-nav {
  flex: 1;
  margin-left: 32px;
}

.main-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background .2s;
}

.main-nav a:hover,
.main-nav a.active {
  background: var(--accent);
  color: var(--primary);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  transition: background .2s;
}

.icon-btn:hover {
  background: var(--accent);
}

main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.upload-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 20px;
  background: var(--card);
  cursor: pointer;
  transition: border .2s, background .2s;
  text-align: center;
}

.upload-card:hover,
.upload-card.dragging {
  border-color: var(--primary);
  background: var(--accent);
}

.upload-card input {
  display: none;
}

.upload-icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
}

.upload-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.upload-tip {
  font-size: 13px;
  color: var(--text);
  opacity: .6;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.book-grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text);
  opacity: .6;
  padding: 40px 0;
  font-size: 15px;
}

.book-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform .2s, box-shadow .2s;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.book-cover {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--primary);
}

.book-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  text-align: center;
  word-break: break-all;
  line-height: 1.3;
}

.book-meta {
  font-size: 13px;
  color: var(--text);
  opacity: .7;
  margin-bottom: 12px;
}

.book-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background .2s, color .2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: var(--primary);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
}

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

.btn-read {
  flex: 1;
  justify-content: center;
}

.btn-delete {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-delete:hover {
  background: #e74c3c;
  border-color: #e74c3c;
}

.view {
  width: 100%;
}

#reader {
  display: flex;
  gap: 16px;
}

.reading-area {
  flex: 1;
  min-width: 0;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--card);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.reader-toolbar .book-title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0;
  text-align: left;
  word-break: normal;
  line-height: normal;
}

.speech-controls {
  display: flex;
  gap: 6px;
}

.sentence {
  border-radius: 4px;
  transition: background 0.3s, box-shadow 0.3s;
  cursor: pointer;
  padding: 4px 8px;
}

.sentence:hover {
  background: var(--primary-hover);/*#ffeaa7*/
}

.sentence.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-hover);
}

.sentence.played {
  background: #dfe6e9;
  color: #636e72;
}

#chapterContent {
  background: var(--reader-bg);
  color: var(--reader-text);
  padding: 30px 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  min-height: 60vh;
  box-shadow: var(--shadow);
}

#chapterTitle {
  font-size: 24px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
}

#chapterText p {
  font-size: var(--content-font-size);
  line-height: var(--content-line-height);
  font-family: var(--content-font-family);
  margin-bottom: 1em;
  text-indent: 2em;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.chapter-index {
  font-size: 14px;
  color: var(--text);
  opacity: .8;
}

.drawer {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  position: sticky;
  top: 72px;
}

.drawer-header {
  font-weight: 600;
  padding: 8px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.chapter-list {
  display: flex;
  flex-direction: column;
}

.chapter-item {
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  transition: background .2s;
}

.chapter-item:hover,
.chapter-item.active {
  background: var(--primary);
  color: #fff;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 20px;
  box-shadow: -2px 0 8px rgba(0, 0, 0, .1);
  z-index: 1000;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  top: 0;
  height: 30px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-size: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.setting-row input[type=range] {
  width: 100%;
}

.theme-buttons {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.theme-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}

input[type="checkbox"] {
  margin-right: 6px;
}

.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 13px;
  opacity: .7;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: .9;
  z-index: 2000;
  transition: opacity .3s;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 16px;
  }
  .main-nav {
    margin-left: 16px;
  }
  main {
    padding: 16px;
  }
  #reader {
    flex-direction: column;
  }
  .drawer {
    width: 100%;
    max-height: 240px;
    position: static;
  }
  #chapterContent {
    padding: 20px 16px;
  }
  .reader-toolbar {
    gap: 4px;
  }
  .book-title {
    max-width: 120px;
  }
}

@media (max-width: 480px) {
  .logo span {
    display: block;
  }
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .speech-controls {
    gap: 2px;
  }
}
