:root {
  --bg: #0c0b0a;
  --bg-2: #141210;
  --surface: #1c1916;
  --ink: #f3ebe1;
  --muted: #9c9186;
  --faint: #5e564e;
  --line: rgba(243, 235, 225, 0.08);
  --accent: #e48a4a;
  --accent-2: #f0c27a;
  --accent-ink: #1a120c;
  --danger: #e06b6b;
  --highlight: rgba(228, 138, 74, 0.16);
  --ui: "PingFang SC", "SF Pro Text", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --read: "Songti SC", "STSong", "Noto Serif SC", Georgia, serif;
  --pad: 20px;
  --bar-h: 72px;
  --radius: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4eee6;
    --bg-2: #efe7db;
    --surface: #fffaf3;
    --ink: #1f1914;
    --muted: #6d6258;
    --faint: #b3a79b;
    --line: rgba(31, 25, 20, 0.08);
    --accent: #c45d28;
    --accent-2: #9a3b2a;
    --accent-ink: #fffaf3;
    --danger: #b42318;
    --highlight: rgba(196, 93, 40, 0.14);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
#audio, #preview {
  position: absolute;
  width: 1px;
  height: 1px;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 16px)
    var(--pad)
    calc(env(safe-area-inset-bottom) + var(--bar-h) + 28px);
}

body.has-bar #app {
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--bar-h) + 28px);
}

.top {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 22px;
}
.brand {
  font-family: var(--read);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.12em;
  margin: 0;
}
.sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.grow { flex: 1; min-width: 0; }

.ghost, .chip, .icon-btn {
  min-height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
}
.chip, .icon-btn {
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.chip.primary, .play {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.icon-btn.danger { color: var(--danger); }

.section-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 8px 0 12px;
}
.section-h h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero {
  width: 100%;
  cursor: pointer;
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 16px;
  align-items: center;
  text-align: left;
  background: linear-gradient(135deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 14px;
  margin-bottom: 22px;
}
.hero .cover {
  width: 92px;
  height: 124px;
  border-radius: 8px;
}
.hero h3 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hero p { margin: 0; color: var(--muted); font-size: 13px; }
.hero .play {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 14px;
}

.cover, .cover-fallback {
  object-fit: cover;
  background: linear-gradient(160deg, #8a3a2a, #2b2118);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}
.cover-fallback {
  display: grid;
  place-items: center;
  color: #f3ebe1;
  font-family: var(--read);
  font-size: 28px;
}

.rail {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 0 16px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.rail::-webkit-scrollbar { display: none; }
.rail-card {
  flex: 0 0 112px;
  scroll-snap-align: start;
  text-align: left;
}
.rail-card .cover, .rail-card .cover-fallback {
  width: 112px;
  height: 148px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.rail-card h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-card p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }

.book-row {
  width: 100%;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
  text-align: left;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.book-row .cover, .book-row .cover-fallback {
  width: 56px;
  height: 74px;
  border-radius: 6px;
}
.book-row h3 { margin: 0 0 4px; font-size: 16px; }
.book-row p { margin: 0; color: var(--muted); font-size: 12px; }

.progress {
  height: 3px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 10px;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
}

.empty {
  text-align: center;
  padding: 48px 12px;
  color: var(--muted);
}
.empty h2 { font-family: var(--read); color: var(--ink); margin: 0 0 8px; }

.hidden-file { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; }

.book-hero {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 12px;
  margin: 8px 0 20px;
}
.book-hero .cover, .book-hero .cover-fallback {
  width: 160px;
  height: 214px;
  border-radius: 10px;
}
.book-hero h1 {
  margin: 8px 0 0;
  font-size: 22px;
  line-height: 1.35;
}
.play-lg {
  width: min(100%, 280px);
  height: 52px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  letter-spacing: 0.06em;
}
.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.play-lg:disabled { opacity: 0.35; }
.convert-line {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 18px;
  text-align: center;
}

.chapter {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.chapter .n { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 13px; }
.chapter h4 { margin: 0; font-size: 15px; font-weight: 500; }
.chapter small { color: var(--muted); }
.chapter:disabled { opacity: 0.42; }
.chapter.is-current h4 { color: var(--accent); }
.chapter.partial small { color: var(--accent-2); }

.sheet {
  margin: 10px 0 18px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.sheet label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 6px; }
.sheet select {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 12px;
}

.reader {
  font-family: var(--read);
  font-size: 21px;
  line-height: 1.9;
  letter-spacing: 0.03em;
  padding: 8px 4px 180px;
}
.reader p {
  margin: 0 0 1.15em;
  padding: 2px 8px;
  border-left: 2px solid transparent;
  transition: color 180ms var(--ease), background 180ms var(--ease), border-color 180ms var(--ease);
}
.reader p.past { color: var(--muted); }
.reader p.current {
  background: var(--highlight);
  border-left-color: var(--accent);
  color: var(--ink);
  border-radius: 0 8px 8px 0;
}

#now {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 0;
}
#now.is-open {
  display: flex;
}
.now-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--pad);
}
.now-titles { text-align: center; }
#now-book {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#now-chapter {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#reader {
  flex: 1;
  overflow: auto;
  padding-left: var(--pad);
  padding-right: var(--pad);
  -webkit-overflow-scrolling: touch;
}
.now-dock {
  position: relative;
  z-index: 2;
  padding: 8px var(--pad) calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.times {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 18px;
}
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}
.play {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 600;
}
.skip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  font-size: 13px;
}

.bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(760px, 100%);
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.bar-progress {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: var(--line);
}
.bar-progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}
.bar-main {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  min-width: 0;
}
.bar-main img, .bar-main .cover-fallback {
  width: 40px;
  height: 52px;
  border-radius: 4px;
  object-fit: cover;
}
.bar-text { min-width: 0; }
#bar-title, #bar-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#bar-title { font-size: 14px; font-weight: 600; }
#bar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bar-play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
  pointer-events: none;
}

.note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 14px;
  margin-bottom: 18px;
}
.note strong { color: var(--ink); font-weight: 600; }

.cta { display: grid; gap: 10px; margin: 8px 0 22px; justify-items: center; }
.linkish {
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.voice-box {
  width: min(100%, 360px);
  text-align: left;
  margin-top: 8px;
}
.voice-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.voice-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.4;
}
.voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.voice-row select {
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 12px;
}
.eta {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 8px;
  line-height: 1.45;
}
.eta strong { color: var(--accent-2); font-weight: 600; }
