:root {
  color-scheme: light;
  --bg: #f6efe4;
  --panel: rgba(246, 239, 228, 0.94);
  --text: #2c241d;
  --muted: #837567;
  --line: rgba(75, 57, 42, 0.14);
  --accent: #8f4d35;
  --shadow: 0 18px 50px rgba(44, 36, 29, 0.16);
  --font-size: 20px;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.theme-night {
  color-scheme: dark;
  --bg: #151413;
  --panel: rgba(21, 20, 19, 0.94);
  --text: #ddd3c5;
  --muted: #948a7c;
  --line: rgba(221, 211, 197, 0.13);
  --accent: #d09778;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

button {
  color: inherit;
  font: inherit;
  border: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  min-height: 100vh;
  min-height: 100svh;
}

.topbar,
.bottom-bar {
  position: fixed;
  z-index: 10;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  background: var(--panel);
  border-color: var(--line);
  backdrop-filter: blur(18px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.topbar {
  top: 0;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}

.bottom-bar {
  bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 0 14px env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  gap: 12px;
}

body.chrome-hidden .topbar {
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: none;
}

body.chrome-hidden .bottom-bar {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  border-radius: 8px;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 2px 0;
  background: currentColor;
  border-radius: 2px;
}

.text-size {
  font-weight: 700;
}

.shelf-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 10px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.top-title {
  min-width: 0;
  flex: 1;
}

.top-title strong,
.drawer-head strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
  line-height: 1.35;
}

.top-title small,
.drawer-head small,
.chapter-heading p,
.chapter-heading span,
.progress-wrap small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.reader {
  box-sizing: border-box;
  max-width: 760px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(82px + env(safe-area-inset-top)) 22px
    calc(96px + env(safe-area-inset-bottom));
  outline: 0;
}

.chapter-heading {
  padding: 8px 0 26px;
  border-bottom: 1px solid var(--line);
}

.chapter-heading h1 {
  margin: 8px 0 6px;
  font-size: 28px;
  line-height: 1.28;
  font-weight: 700;
  letter-spacing: 0;
}

.chapter-audio {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.24);
}

body.theme-night .chapter-audio {
  background: rgba(255, 255, 255, 0.04);
}

.chapter-audio[hidden] {
  display: none;
}

.chapter-audio-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chapter-audio-meta strong {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 14px;
  line-height: 1.4;
}

.chapter-audio-meta span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}

.chapter-audio audio {
  display: block;
  width: 100%;
  height: 38px;
}

.chapter-audio-open {
  width: 100%;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.chapter-body {
  padding-top: 16px;
  font-size: var(--font-size);
  line-height: 1.92;
  text-align: justify;
  word-break: break-word;
}

.chapter-body p {
  margin: 0 0 1.05em;
}

.chapter-body p.dialogue {
  margin-top: 0.6em;
}

.bottom-bar button {
  flex: 0 0 auto;
  min-width: 62px;
  height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--accent);
}

.bottom-bar button:disabled {
  opacity: 0.36;
}

.progress-wrap {
  min-width: 0;
  flex: 1;
}

.progress-track {
  height: 3px;
  overflow: hidden;
  background: var(--line);
  border-radius: 99px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.progress-wrap small {
  margin-top: 4px;
  text-align: center;
}

.drawer,
.settings {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  background: rgba(0, 0, 0, 0.28);
}

.drawer.open,
.settings.open {
  display: block;
}

.drawer-panel {
  box-sizing: border-box;
  width: min(86vw, 360px);
  height: 100%;
  padding: calc(18px + env(safe-area-inset-top)) 0
    calc(18px + env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-head div {
  min-width: 0;
}

#closeDrawer {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 8px;
  font-size: 24px;
  line-height: 1;
}

#chapterList {
  height: calc(100% - 72px);
  margin: 0;
  padding: 8px 0 0;
  list-style: none;
  overflow: auto;
}

#chapterList button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 14px;
  box-sizing: border-box;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

#chapterList button strong {
  font-size: 16px;
  line-height: 1.4;
}

#chapterList button span,
#chapterList button small {
  color: var(--muted);
  font-size: 12px;
}

#chapterList button.current strong {
  color: var(--accent);
}

#chapterList button:disabled {
  opacity: 0.45;
}

.settings {
  background: rgba(0, 0, 0, 0.18);
}

.settings-panel {
  position: absolute;
  right: 12px;
  top: calc(62px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  gap: 8px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-panel button {
  height: 38px;
  border-radius: 8px;
  background: var(--line);
}

.wechat-guide {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  box-sizing: border-box;
  padding: calc(34px + env(safe-area-inset-top)) 18px
    calc(24px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
}

.wechat-guide.open {
  display: block;
}

.wechat-arrow {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 24px;
  font-size: 42px;
  line-height: 1;
}

.wechat-card {
  box-sizing: border-box;
  margin: 58px auto 0;
  max-width: 360px;
  padding: 22px 20px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.wechat-card strong {
  display: block;
  font-size: 22px;
  line-height: 1.35;
}

.wechat-card p {
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.wechat-card button {
  width: 100%;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.wechat-card small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.audio-player-view {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

.audio-player-view.open {
  display: block;
}

body.audio-mode .topbar,
body.audio-mode .bottom-bar {
  opacity: 0;
  pointer-events: none;
}

.audio-player-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-sizing: border-box;
  width: min(100%, 520px);
  height: 100%;
  min-height: 100svh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 50% 0, rgba(143, 77, 53, 0.18), transparent 46%),
    var(--bg);
}

.audio-player-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-sizing: border-box;
  min-height: calc(58px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  border-bottom: 1px solid var(--line);
}

.audio-player-top button {
  height: 40px;
  border-radius: 8px;
  color: var(--accent);
  font-weight: 700;
}

.audio-player-top span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-player-main {
  min-height: 0;
  overflow: hidden;
  padding: 22px 22px 12px;
  text-align: center;
}

.audio-poster-wrap {
  position: relative;
  width: min(58vw, 230px);
  aspect-ratio: 3 / 4;
  margin: 0 auto 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #1e1a17, var(--accent), #ead7bd);
  box-shadow: var(--shadow);
}

.audio-poster-wrap img,
.audio-poster-fallback {
  width: 100%;
  height: 100%;
}

.audio-poster-wrap img {
  display: block;
  object-fit: cover;
}

.audio-poster-fallback {
  display: grid;
  place-items: center;
  padding: 18px;
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
}

.audio-poster-fallback[hidden],
.audio-poster-wrap img[hidden] {
  display: none;
}

.audio-book-title {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.audio-player-main h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
}

.audioVoiceLabels {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.audio-subtitles {
  height: min(28vh, 210px);
  overflow: auto;
  padding: 14px 8px 44px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  scroll-behavior: smooth;
}

.audio-subtitles p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
  transition: color 0.18s ease, font-size 0.18s ease;
}

.audio-subtitles p.active {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.audio-subtitles .empty-subtitle {
  margin-top: 54px;
  color: var(--muted);
}

.audio-player-controls {
  box-sizing: border-box;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
}

.audio-player-controls audio {
  display: block;
  width: 100%;
  height: 40px;
}

.bookshelf-page {
  min-height: 100vh;
  min-height: 100svh;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 155, 173, 0.42), transparent 34%),
    radial-gradient(circle at 88% 18%, rgba(143, 77, 53, 0.18), transparent 32%),
    linear-gradient(180deg, #fff8ee 0%, var(--bg) 45%, #eadfce 100%);
}

.bookshelf-shell {
  box-sizing: border-box;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: calc(34px + env(safe-area-inset-top)) 18px
    calc(36px + env(safe-area-inset-bottom));
}

.bookshelf-hero {
  padding: 14px 2px 24px;
}

.bookshelf-hero p {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.bookshelf-hero h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 64px);
  line-height: 1;
  letter-spacing: -0.06em;
}

.bookshelf-hero span {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.bookshelf-list {
  display: grid;
  gap: 18px;
}

.bookshelf-card {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 18px;
  box-sizing: border-box;
  padding: 16px;
  border: 1px solid rgba(75, 57, 42, 0.12);
  border-radius: 22px;
  background: rgba(255, 252, 246, 0.82);
  box-shadow: 0 18px 50px rgba(44, 36, 29, 0.12);
  backdrop-filter: blur(16px);
}

.book-cover {
  position: relative;
  display: block;
  width: 118px;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(135deg, #ff9bad, #8f4d35 52%, #171116);
  box-shadow: 0 16px 32px rgba(44, 36, 29, 0.22);
  text-decoration: none;
}

.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover span {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 14px;
  color: #fff7ef;
  font-size: 24px;
  font-weight: 800;
  text-align: center;
}

.book-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.book-kicker,
.book-count,
.book-progress {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.book-info h2 {
  margin: 5px 0 8px;
  font-size: 24px;
  line-height: 1.25;
}

.book-count {
  color: var(--accent);
  font-weight: 700;
}

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

.book-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-top: auto;
  padding: 0 18px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

button.book-cover {
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.bookshelf-card-grouped {
  grid-template-columns: 118px 1fr;
}

.bookshelf-card-grouped .book-parts {
  grid-column: 1 / -1;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(75, 57, 42, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.book-parts-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.part-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(75, 57, 42, 0.15);
  border-radius: 14px;
  background: rgba(255, 252, 246, 0.6);
  text-decoration: none;
  color: inherit;
  transition: background 0.18s ease, transform 0.18s ease;
}

.part-row:hover {
  background: rgba(255, 252, 246, 1);
  transform: translateY(-1px);
}

.part-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.part-row-main strong {
  font-size: 16px;
  font-weight: 800;
}

.part-row-main small {
  font-size: 12px;
  color: var(--muted);
}

.part-row-action {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.bookshelf-card-grouped.expanded .book-action {
  background: rgba(75, 57, 42, 0.12);
  color: var(--accent);
}

@media (min-width: 680px) {
  .reader {
    padding-right: 34px;
    padding-left: 34px;
  }

  .bookshelf-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .topbar {
    gap: 7px;
  }

  .shelf-link {
    padding: 0 8px;
    font-size: 12px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .bookshelf-card {
    grid-template-columns: 96px 1fr;
    gap: 14px;
    padding: 14px;
    border-radius: 18px;
  }

  .book-cover {
    width: 96px;
    border-radius: 13px;
  }

  .book-info h2 {
    font-size: 21px;
  }

  .chapter-audio-meta {
    display: block;
  }

  .chapter-audio-meta span {
    margin-top: 3px;
    text-align: left;
  }

  .audio-player-main {
    padding-right: 18px;
    padding-left: 18px;
  }

  .audio-player-main h2 {
    font-size: 20px;
  }
}
