:root {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --accent: #007aff;
  --accent-sec: #34c759;
  --border: #e5e5ea;
  --shadow: rgba(0, 0, 0, 0.08);
  --font-size: 18px;
  --line-height: 1.8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --text: #f2f2f7;
  --muted: #8e8e93;
  --accent: #0a84ff;
  --accent-sec: #30d158;
  --border: #38383a;
  --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #efe6d0;
  --text: #433422;
  --muted: #8a7e6b;
  --accent: #8b5a2b;
  --accent-sec: #5d8c3a;
  --border: #dcd1bc;
  --shadow: rgba(67, 52, 34, 0.1);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  height: 100%;
  width: 100%;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

.view.active {
  display: flex;
}

/* 通用按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-btn.disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* 书库 */
.app-header {
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
}

.library-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.empty-tip {
  text-align: center;
  color: var(--muted);
  margin-top: 40px;
}

.book-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.book-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 2px 8px var(--shadow);
  cursor: pointer;
  transition: transform 0.1s;
}

.book-item:active {
  transform: scale(0.98);
}

.book-thumb {
  width: 56px;
  height: 72px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-sec));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 24px;
  flex-shrink: 0;
}

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

.book-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-meta {
  font-size: 13px;
  color: var(--muted);
}

.book-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.book-progress > div {
  height: 100%;
  background: var(--accent);
}

.book-delete {
  flex-shrink: 0;
  color: #ff3b30;
  font-size: 20px;
  background: transparent;
}

/* 普通阅读器 */
.reader-header {
  padding: calc(10px + var(--safe-top)) 12px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.reader-header h2 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: var(--font-size);
  line-height: var(--line-height);
  white-space: pre-wrap;
  word-break: break-word;
}

.reader-footer {
  padding: 10px 16px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#reader-progress {
  width: 100%;
}

.reader-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.reader-pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  padding: 4px 10px;
  cursor: pointer;
}

.pager-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* 速度阅读器 */
.speed-header {
  padding: calc(10px + var(--safe-top)) 12px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.speed-header h2 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  text-align: center;
}

.speed-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
}

.speed-word {
  font-size: clamp(48px, 18vw, 120px);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  min-height: 1.4em;
  color: var(--text);
}

.speed-guide {
  margin-top: 12px;
  font-size: 16px;
  color: var(--muted);
  text-align: center;
  min-height: 1.4em;
}

.speed-progress-wrap {
  padding: 12px 16px 0;
}

#speed-progress {
  width: 100%;
}

.speed-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.speed-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 16px 0;
}

.play-btn {
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px var(--shadow);
}

.speed-slider-wrap {
  padding: 0 20px calc(20px + var(--safe-bottom));
  text-align: center;
}

.speed-slider-wrap label {
  display: block;
  margin-bottom: 8px;
  font-size: 15px;
  color: var(--muted);
}

#speed-slider {
  width: 100%;
}

/* 设置面板 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -4px 20px var(--shadow);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal-content label {
  display: block;
  margin-bottom: 16px;
  font-size: 15px;
}

.modal-content input,
.modal-content select {
  display: block;
  width: 100%;
  margin-top: 8px;
  font-size: 15px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.modal-actions {
  text-align: right;
}

input[type="range"] {
  accent-color: var(--accent);
}

/* 滚动条精简 */
::-webkit-scrollbar {
  width: 6px;
}

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