:root {
  --bg: #0f0f12;
  --bg-elevated: #1a1a20;
  --bg-card: #20202a;
  --bg-hover: #2a2a35;
  --text: #e8e8ea;
  --text-dim: #9090a0;
  --accent: #f0a060;
  --accent-hover: #ffb978;
  --accent-dim: #8a5a3a;
  --border: #2a2a35;
  --success: #6ec78c;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  min-height: 100%;
}

body {
  overflow-y: auto;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

/* 通用 header */
header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-dim);
}

.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 16px;
}

#stats-text {
  font-variant-numeric: tabular-nums;
}

#reset-btn, .back-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

#reset-btn:hover, .back-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.back-btn {
  margin-bottom: 8px;
  font-size: 13px;
}

/* ============ 书架（首页）============ */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  padding: 24px 32px 40px;
}

.book-card {
  display: flex;
  background: var(--bg-elevated);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  border: 1px solid var(--border);
  cursor: pointer;
}

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

.book-cover {
  flex-shrink: 0;
  width: 110px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 16px 10px;
  color: rgba(255,255,255,0.9);
  text-align: center;
  position: relative;
}

.cover-emoji {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

.cover-era {
  font-size: 11px;
  letter-spacing: 0.15em;
  opacity: 0.85;
  writing-mode: vertical-rl;
  text-orientation: upright;
  margin-top: 8px;
}

.book-info {
  flex: 1;
  padding: 14px 16px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.book-info h2 {
  margin: 0 0 2px;
  font-size: 18px;
  font-weight: 600;
}

.book-subtitle {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.book-meta {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.book-meta span:not(:first-child):not(:nth-child(2)) {
  color: var(--border);
}

.book-desc {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.book-progress {
  margin-top: auto;
  padding-top: 8px;
}

.progress-bar {
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.listen-btn {
  background: var(--accent);
  color: #0f0f12;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}

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

.book-voice {
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-dim);
  text-align: right;
  opacity: 0.7;
}

.loading, .empty {
  padding: 60px 32px;
  text-align: center;
  color: var(--text-dim);
}

.empty code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

footer {
  padding: 20px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

footer code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ============ 播放器 ============ */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.chapters {
  width: 340px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.chapters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px 8px;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 2;
}

.chapters-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

#chapter-list {
  list-style: none;
  margin: 0;
  padding: 4px 0 20px;
}

.chapter-item {
  padding: 12px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  transition: background 0.15s, border-color 0.15s;
}

.chapter-item:hover {
  background: var(--bg-card);
}

.chapter-item.current {
  background: var(--bg-card);
  border-left-color: var(--accent);
}

.chapter-item.completed .chapter-num {
  color: var(--success);
}

.chapter-num {
  flex-shrink: 0;
  min-width: 36px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.chapter-info {
  flex: 1;
  min-width: 0;
}

.chapter-title {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

.chapter-duration {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.chapter-item.current .chapter-title {
  color: var(--accent);
}

.player {
  flex: 1;
  padding: 32px 32px 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  min-height: 0;
}

#show-chapters {
  display: none;
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 5;
}

.now-playing {
  text-align: center;
  margin: 32px 0 36px;
  flex-shrink: 0;
}

.chapter-num {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

#cur-num {
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
}

.chapter-title {
  font-size: 19px;
  font-weight: 500;
  line-height: 1.5;
  max-width: 600px;
  margin: 0 auto;
  color: var(--text);
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.ctrl-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
}

.ctrl-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.play-btn {
  background: var(--accent);
  border: none;
  color: #0f0f12;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.play-btn.playing {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 160, 96, 0.3); }
  50% { box-shadow: 0 0 0 12px rgba(240, 160, 96, 0); }
}

.progress {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.progress span {
  font-size: 13px;
  color: var(--text-dim);
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#seek-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s;
}

#seek-bar::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

#seek-bar::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.bottom-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.speed-control select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}

.speed-control select:focus {
  outline: none;
  border-color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

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

.mobile-only {
  display: none;
}

/* 移动端 */
@media (max-width: 768px) {
  header {
    padding: 18px 16px 14px;
  }
  
  header h1 {
    font-size: 21px;
  }
  
  .shelf {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  
  main {
    flex-direction: column;
  }
  
  .chapters {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.25s;
    box-shadow: var(--shadow);
  }
  
  .chapters.open {
    transform: translateX(0);
  }
  
  #show-chapters {
    display: block;
  }
  
  .player {
    padding: 60px 20px 20px;
  }
  
  .now-playing {
    margin: 16px 0 24px;
  }
  
  .chapter-title {
    font-size: 16px;
  }
  
  .controls {
    gap: 12px;
  }
  
  .ctrl-btn {
    width: 44px;
    height: 44px;
    font-size: 12px;
  }
  
  .play-btn {
    width: 64px;
    height: 64px;
    font-size: 24px;
  }
  
  .bottom-controls {
    gap: 16px;
    flex-wrap: wrap;
  }
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: #40404a;
}