:root {
  --bg: #181410;
  --bg-soft: #20191322;
  --panel: #241d16;
  --panel-2: #2c2319;
  --line: #3a2e22;
  --ink: #efe6d8;
  --ink-soft: #c9bba6;
  --ink-faint: #8c7e6a;
  --gold: #d8a85b;
  --gold-soft: #e7c489;
  --rose: #c97b62;
  --green: #7fae6e;
  --radius: 14px;
  --shadow: 0 18px 50px -20px rgba(0,0,0,.7);
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Noto Sans SC", -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
[data-theme="paper"] {
  --bg: #efe7d8;
  --bg-soft: #00000008;
  --panel: #fbf6ea;
  --panel-2: #f3ead7;
  --line: #ddcfb5;
  --ink: #3a2f22;
  --ink-soft: #6b5c46;
  --ink-faint: #9a8a72;
  --gold: #b07d2c;
  --gold-soft: #936518;
  --rose: #b15a3e;
  --shadow: 0 18px 50px -24px rgba(120,90,40,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(216,168,91,.07), transparent),
    radial-gradient(900px 500px at -10% 110%, rgba(201,123,98,.06), transparent);
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  height: 68px; display: flex; align-items: center; gap: 14px;
  padding: 0 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--bg-soft), transparent);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand .logo {
  font-family: var(--serif); font-size: 26px; font-weight: 700;
  letter-spacing: 4px; color: var(--gold);
}
.brand .tag { font-size: 12.5px; color: var(--ink-faint); letter-spacing: 1px; }
.topbar .spacer { flex: 1; }
.status {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
  color: var(--ink-faint); padding: 6px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg-soft);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); }
.status .dot.ok { background: var(--green); box-shadow: 0 0 10px var(--green); }
.status .dot.loading { background: var(--gold); animation: pulse 1.2s infinite; }
.status .dot.err { background: var(--rose); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.25} }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--ink-soft); cursor: pointer; font-size: 17px;
  display: grid; place-items: center; transition: .18s;
}
.icon-btn:hover { color: var(--gold); border-color: var(--gold); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100% - 68px); }

/* ---------- sidebar ---------- */
.sidebar {
  border-right: 1px solid var(--line); padding: 22px 18px; overflow: hidden;
  display: flex; flex-direction: column; gap: 18px;
}
.side-title {
  font-family: var(--serif); font-size: 18px; letter-spacing: 2px;
  display: flex; align-items: center; gap: 8px; color: var(--ink);
}
.side-title i { color: var(--gold); }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 22px 14px; text-align: center; cursor: pointer; transition: .2s;
  background: var(--bg-soft);
}
.dropzone:hover, .dropzone.drag { border-color: var(--gold); background: rgba(216,168,91,.06); }
.dropzone i { font-size: 26px; color: var(--gold); }
.dropzone p { font-size: 13px; color: var(--ink-soft); margin-top: 8px; }
.dropzone small { color: var(--ink-faint); font-size: 11.5px; }

.booklist { display: flex; flex-direction: column; gap: 10px; flex: 1; overflow-y: auto; min-height: 40px; }

/* ---------- GPU monitor ---------- */
.gpu-monitor { flex: none; border: 1px solid var(--line); background: var(--bg-soft); }
.top-gpu {
  width: auto; min-width: 250px; border-radius: 12px; padding: 7px 10px;
  display: flex; align-items: center; gap: 12px;
}
.gpu-head {
  font-size: 12px; color: var(--ink-soft); display: flex; align-items: center;
  gap: 5px; letter-spacing: .3px; flex: none;
}
.gpu-head i { color: var(--gold); font-size: 15px; }
.gpu-busy {
  font-size: 10px; color: #2a2013; background: var(--gold);
  padding: 1px 8px; border-radius: 99px; display: none;
}
.gpu-busy.on { display: inline-block; animation: pulse 1.1s infinite; }
.gpu-row {
  display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-faint);
}
.gpu-lbl { width: 28px; flex: none; }
.meter { flex: 1; height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 4px; transition: width .4s, background .4s; }
.top-gpu .meter { display: none; }
.gpu-row b { color: var(--ink-soft); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.book-card {
  display: flex; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent; transition: .15s; position: relative;
}
.book-card:hover { background: var(--panel); border-color: var(--line); }
.book-card.active { background: var(--panel-2); border-color: var(--gold); }
.book-cover {
  width: 46px; height: 64px; border-radius: 6px; flex: none; object-fit: cover;
  background: linear-gradient(135deg, #3a2c1d, #5a4127); display: grid; place-items: center;
  color: var(--gold-soft); font-family: var(--serif); font-size: 22px; overflow: hidden;
  box-shadow: 0 6px 14px -6px rgba(0,0,0,.6);
}
.book-meta { min-width: 0; flex: 1; }
.book-meta h4 {
  font-size: 14px; font-weight: 500; font-family: var(--serif); color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-meta p { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-del {
  position: absolute; top: 8px; right: 8px; opacity: 0; color: var(--ink-faint);
  background: none; border: none; cursor: pointer; font-size: 15px; transition: .15s;
}
.book-card:hover .book-del { opacity: 1; }
.book-del:hover { color: var(--rose); }
.empty-mini { font-size: 12.5px; color: var(--ink-faint); text-align: center; padding: 10px; }

/* ---------- content ---------- */
.content { overflow-y: auto; position: relative; }
.welcome {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; gap: 14px; color: var(--ink-faint);
}
.welcome .big { font-size: 64px; color: var(--gold); opacity: .8; }
.welcome h2 { font-family: var(--serif); font-size: 26px; color: var(--ink); letter-spacing: 2px; }
.welcome p { max-width: 420px; font-size: 14px; }

.reader { padding: 30px 40px 160px; max-width: 920px; margin: 0 auto; }
.book-hero { display: flex; gap: 24px; align-items: flex-end; margin-bottom: 26px; }
.hero-cover {
  width: 120px; height: 168px; border-radius: 10px; flex: none; object-fit: cover;
  background: linear-gradient(135deg, #3a2c1d, #5a4127); display: grid; place-items: center;
  color: var(--gold-soft); font-family: var(--serif); font-size: 40px; box-shadow: var(--shadow);
}
.hero-info h1 { font-family: var(--serif); font-size: 30px; font-weight: 700; letter-spacing: 1px; }
.hero-info .author { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }
.hero-info .stat { color: var(--ink-faint); font-size: 13px; margin-top: 10px; }

.controls {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 24px;
}
.ctl { display: flex; flex-direction: column; gap: 4px; }
.ctl label { font-size: 11px; color: var(--ink-faint); letter-spacing: .5px; }
select, .seg-range {
  background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; font-size: 13px; font-family: var(--sans); cursor: pointer;
}
select:focus { outline: none; border-color: var(--gold); }
[data-theme="night"] select { color-scheme: dark; }
[data-theme="paper"] select { color-scheme: light; }
select option {
  background: #241d16;
  color: #efe6d8;
}
select option:checked {
  background: #d8a85b;
  color: #2a2013;
}
[data-theme="paper"] select option {
  background: #fbf6ea;
  color: #3a2f22;
}
.btn-preview {
  background: none; border: 1px solid var(--line); color: var(--ink-soft);
  padding: 8px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; transition: .15s;
}
.btn-preview:hover { border-color: var(--gold); color: var(--gold); }

/* chapter list */
.section-h { font-family: var(--serif); font-size: 17px; margin: 8px 0 12px; letter-spacing: 1px; color: var(--ink); }
.chapters { display: flex; flex-direction: column; gap: 2px; }
.chap {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  cursor: pointer; border: 1px solid transparent; transition: .14s;
}
.chap:hover { background: var(--panel); }
.chap.active { background: var(--panel-2); border-color: var(--gold); }
.chap .num { font-family: var(--serif); color: var(--gold); font-size: 14px; width: 30px; flex: none; }
.chap .ct { flex: 1; font-size: 14px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chap.active .ct { color: var(--ink); }
.chap .len { font-size: 11.5px; color: var(--ink-faint); }
.chap .playing-ic { color: var(--gold); display: none; }
.chap.active .playing-ic { display: inline; }

/* reading pane */
.read-pane { margin-top: 8px; }
.seg {
  font-family: var(--serif); font-size: 18.5px; line-height: 2.1; color: var(--ink-soft);
  padding: 4px 10px; border-radius: 8px; transition: .25s; cursor: pointer;
}
.seg:hover { color: var(--ink); }
.seg.current {
  color: var(--ink); background: rgba(216,168,91,.12);
  box-shadow: inset 3px 0 0 var(--gold);
}
.seg.done { color: var(--ink-faint); }

/* ---------- player bar ---------- */
.player {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 30px;
  background: linear-gradient(transparent, var(--bg) 30%);
  display: flex; align-items: center; gap: 20px; transform: translateY(130%); transition: .3s;
}
.player.show { transform: translateY(0); }
.player-inner {
  flex: 1; max-width: 920px; margin: 0 auto; display: flex; align-items: center; gap: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 18px; box-shadow: var(--shadow);
}
.np { min-width: 0; flex: 1; }
.np .t { font-family: var(--serif); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np .s { font-size: 11.5px; color: var(--ink-faint); }
.transport { display: flex; align-items: center; gap: 8px; }
.speed-control {
  height: 40px; display: flex; align-items: center; gap: 6px; flex: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 0 8px 0 11px;
  background: var(--bg-soft); color: var(--ink-soft);
}
.speed-control i { color: var(--gold); font-size: 15px; }
.speed-control select {
  width: 72px; border: none; padding: 0 18px 0 0; border-radius: 0;
  background: transparent; color: var(--ink); font-size: 12.5px;
}
.speed-control select:focus { outline: none; border: none; }
.tbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--ink); cursor: pointer; font-size: 18px;
  display: grid; place-items: center; transition: .15s;
}
.tbtn:hover { border-color: var(--gold); color: var(--gold); }
.tbtn.main {
  width: 52px; height: 52px; background: var(--gold); color: #2a2013; border: none; font-size: 22px;
}
.tbtn.main:hover { background: var(--gold-soft); color: #2a2013; }
.progress { flex: 1.4; display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }
.progress .tlabel { font-size: 11.5px; color: var(--ink-faint); width: 56px; text-align: right; }
.spin {
  width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--gold);
  border-radius: 50%; animation: rot .8s linear infinite; display: none;
}
.spin.show { display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- modal / toast ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-bg.show { display: flex; }
.modal {
  width: 440px; max-width: 92vw; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
  max-height: min(680px, 92vh); overflow-y: auto;
}
.modal h3 { font-family: var(--serif); font-size: 20px; margin-bottom: 6px; }
.modal p.hint { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.field input[type=text], .field input[type=file], .field textarea {
  width: 100%; background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; font-size: 13px; font-family: var(--sans);
}
.field textarea { resize: vertical; min-height: 60px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.btn { padding: 9px 18px; border-radius: 9px; cursor: pointer; font-size: 13px; border: 1px solid var(--line); background: none; color: var(--ink-soft); }
.btn.primary { background: var(--gold); color: #2a2013; border: none; font-weight: 500; }
.btn.primary:hover { background: var(--gold-soft); }
.btn:hover { border-color: var(--gold); color: var(--gold); }

.voice-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.voice-row .vn { flex: 1; }
.voice-row .badge { font-size: 10.5px; color: var(--gold); border: 1px solid var(--line); padding: 1px 7px; border-radius: 99px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  padding: 12px 20px; border-radius: 12px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 80; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--rose); }

.uploading { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--gold); padding: 6px; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 移动端适配（演示版追加）：窄屏改上下堆叠 ===== */
@media (max-width: 700px) {
  body { overflow: auto; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100% - 68px);
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }
  .booklist { max-height: 300px; }
}
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 6px 10px; }
  .topbar .tag { display: none; }
  .gpu-monitor.top-gpu { display: none; }   /* 手机上收起 GPU 监控条 */
  .player { padding: 8px; }
  .player-inner { flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; }
}
