:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --card-hover: #222244;
  --primary: #4a9eff;
  --primary-glow: rgba(74, 158, 255, 0.25);
  --text: #e8e8f0;
  --text-dim: #7a7a9a;
  --radius: 16px;
  --radius-sm: 12px;
  --highlight: rgba(74, 158, 255, 0.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ===== Bookshelf ===== */
#upload-screen { min-height: 100vh; padding: 0 0 80px; display: flex; flex-direction: column; }

.shelf-header {
  background: linear-gradient(180deg, #1a1a3e 0%, transparent 100%);
  padding: 48px 20px 20px; position: sticky; top: 0; z-index: 10;
}
.shelf-top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.logo { font-size: 28px; }
.shelf-title { font-size: 24px; font-weight: 700; }

.drop-zone {
  background: var(--card); border: 2px dashed rgba(74,158,255,0.25);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; align-items: center; gap: 12px; cursor: pointer; transition: all 0.3s;
}
.drop-zone:active, .drop-zone.dragover {
  border-color: var(--primary); background: var(--card-hover);
  box-shadow: 0 0 20px var(--primary-glow);
}
.dz-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(74,158,255,0.15); display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--primary); flex-shrink: 0;
}
.dz-text { font-size: 15px; font-weight: 600; flex: 1; }
.dz-hint { font-size: 12px; color: var(--text-dim); }

.empty-state { text-align: center; padding: 60px 24px; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-text { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.empty-hint { font-size: 14px; color: var(--text-dim); }
.empty-tip { font-size: 12px; color: #88ccff; margin-top: 8px; }

.bookshelf { padding: 8px 16px; display: flex; flex-direction: column; gap: 12px; }

.book-card {
  background: var(--card); border-radius: var(--radius-sm); padding: 16px;
  display: flex; align-items: center; gap: 14px; cursor: pointer; transition: all 0.2s;
}
.book-card:active { background: var(--card-hover); transform: scale(0.98); }

.book-cover {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #4a9eff22, #6c63ff22);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex-shrink: 0;
}
.book-info { flex: 1; min-width: 0; }
.book-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.book-progress { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.bp-label { font-size: 10px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
.bp-track { flex: 1; height: 3px; background: rgba(76,175,80,0.15); border-radius: 3px; overflow: hidden; }
.bp-fill { height: 100%; background: linear-gradient(90deg, #4caf50, #66bb6a); border-radius: 3px; transition: width 0.3s; }
.bp-text { font-size: 10px; color: #4caf50; min-width: 30px; text-align: right; align-self: flex-end; }

.delete-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(255,82,82,0.1); color: #ff5252; font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

.shelf-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 20px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg); font-size: 11px; color: var(--text-dim); text-align: center;
}

/* ===== Player ===== */
#player-screen { display: flex; flex-direction: column; min-height: 100vh; max-width: 600px; margin: 0 auto; padding: 0 16px 20px; }

.player-header {
  display: flex; align-items: center; padding: 12px 0; gap: 12px;
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.back-btn {
  width: 40px; height: 40px; border-radius: 50%; background: var(--card);
  border: none; color: var(--text); font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.back-btn:active { background: var(--card-hover); }
.header-title { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.book-info { text-align: center; padding: 8px 0 12px; }
.book-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.book-meta { font-size: 13px; color: var(--text-dim); }

/* Sentence Highlight */
.sentence-card {
  background: linear-gradient(135deg, #1a1a3e, #16213e);
  border-radius: var(--radius); padding: 32px 24px; margin-bottom: 8px;
  min-height: 100px; display: flex; align-items: center; justify-content: center;
}
.sentence-highlight {
  font-size: 20px; font-weight: 600; line-height: 1.7;
  text-align: center; color: #e8e8f0;
  background: var(--highlight); padding: 12px 20px; border-radius: 12px;
}
.sentence-dim { font-size: 16px; color: var(--text-dim); text-align: center; }

.sentence-counter {
  text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

/* Player Card */
.player-card {
  background: linear-gradient(135deg, #1a1a3e, #16213e);
  border-radius: var(--radius); padding: 20px 20px 16px; margin-bottom: 12px;
}

.progress-area { margin-bottom: 14px; }
.progress-track { height: 4px; background: rgba(255,255,255,0.1); border-radius: 4px; cursor: pointer; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #6c63ff); border-radius: 4px; width: 0%; transition: width 0.3s; }

.controls { display: flex; justify-content: center; align-items: center; gap: 32px; margin-bottom: 14px; }
.ctrl-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.06); color: var(--text); font-size: 20px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.ctrl-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.12); }
.ctrl-btn.main {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--primary), #6c63ff);
  font-size: 26px; box-shadow: 0 4px 20px var(--primary-glow);
}

.speed-row { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.speed-label { font-size: 12px; color: var(--text-dim); margin-right: 4px; }
.speed-btn {
  padding: 4px 12px; border-radius: 14px; border: none;
  background: rgba(255,255,255,0.06); color: var(--text-dim);
  font-size: 12px; cursor: pointer;
}
.speed-btn.active { background: rgba(74,158,255,0.2); color: var(--primary); font-weight: 600; }

/* Sleep Timer */
.timer-card {
  background: var(--card); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px;
}
.timer-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer-label { font-size: 13px; color: var(--text-dim); margin-right: 4px; }
.timer-btn {
  padding: 4px 12px; border-radius: 14px; border: none;
  background: rgba(255,255,255,0.06); color: var(--text-dim);
  font-size: 12px; cursor: pointer;
}
.timer-btn.active { background: rgba(255,193,7,0.2); color: #ffc107; font-weight: 600; }

.timer-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  font-size: 13px; color: #ffc107; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.06);
}
.timer-cancel {
  margin-left: auto; background: none; border: none;
  color: #ff5252; font-size: 12px; cursor: pointer;
}

/* Chapters */
.chapter-section { flex: 1; }
.section-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; padding-left: 8px; border-left: 3px solid var(--primary); color: var(--text); }

.chapter-item {
  display: flex; align-items: center; padding: 10px 12px;
  border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 2px; transition: background 0.2s;
}
.chapter-item:active { background: var(--card); }
.chapter-item.active { background: rgba(74,158,255,0.08); }

.chapter-num {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,0.06); display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-dim); flex-shrink: 0;
}
.chapter-item.active .chapter-num { background: rgba(74,158,255,0.2); color: var(--primary); }
.chapter-text { flex: 1; margin-left: 12px; overflow: hidden; }
.chapter-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-play { margin-left: 8px; font-size: 12px; color: var(--primary); }

.status-overlay { text-align: center; padding: 60px 24px; }
.status-overlay .emoji { font-size: 40px; margin-bottom: 12px; }
.status-overlay .msg { font-size: 14px; color: var(--text-dim); }

/* Upload progress bar - 大而醒目 */
.upload-progress {
  margin: 12px 16px; padding: 16px;
  background: linear-gradient(135deg, rgba(255,165,0,0.08), rgba(74,158,255,0.08));
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 2px rgba(255,165,0,0.25), 0 4px 20px rgba(255,165,0,0.15);
  border-left: 4px solid #ffa500;
}
.upload-progress-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; color: #ffa500;
  margin-bottom: 10px;
}
.upload-progress-icon {
  font-size: 18px; animation: spin 1.5s linear infinite; display: inline-block;
}
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.upload-progress-track {
  height: 10px; background: rgba(255,255,255,0.08);
  border-radius: 6px; overflow: hidden; position: relative;
}
.upload-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffa500, #ff6b6b, #ffa500);
  background-size: 200% 100%;
  border-radius: 6px; transition: width 0.25s ease; width: 0%;
  animation: progress-shimmer 1.5s linear infinite, gradient-flow 2s ease infinite;
  box-shadow: 0 0 10px rgba(255,165,0,0.7);
}
@keyframes progress-shimmer {
  0%, 100% { opacity: 0.85; filter: brightness(1); }
  50% { opacity: 1; filter: brightness(1.3); }
}
@keyframes gradient-flow {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
.upload-progress-fill.done {
  animation: none; opacity: 1;
  background: linear-gradient(90deg, #4caf50, #66bb6a);
}
.upload-progress-label {
  font-size: 13px; color: var(--text);
  margin-top: 10px; text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Status messages */
.loading-status {
  text-align: center; padding: 12px 16px; margin: 8px 16px;
  background: rgba(74,158,255,0.1); border-radius: var(--radius-sm);
  color: var(--primary); font-size: 14px;
}
.error-status {
  text-align: center; padding: 12px 16px; margin: 8px 16px;
  background: rgba(255,82,82,0.1); border-radius: var(--radius-sm);
  color: #ff5252; font-size: 14px;
}

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--card); color: var(--text); padding: 10px 20px;
  border-radius: var(--radius-sm); font-size: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4); z-index: 100;
  animation: toastIn 0.3s ease;
  white-space: nowrap; max-width: 80vw; overflow: hidden; text-overflow: ellipsis;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
