:root {
  --bg: #e8e4dc;
  --bg-soft: #f3efe6;
  --ink: #1c1a17;
  --ink-muted: #6b6458;
  --accent: #8b3a2a;
  --accent-soft: rgba(139, 58, 42, 0.12);
  --line: rgba(28, 26, 23, 0.12);
  --panel: #faf7f0;
  --shadow: 0 18px 48px rgba(28, 26, 23, 0.12);
  --font-body: "Noto Serif SC", "Songti SC", serif;
  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --reader-size: 18px;
  --reader-lh: 1.9;
  --reader-max: 42rem;
}

[data-theme="ink"] {
  --bg: #12141a;
  --bg-soft: #1a1d26;
  --ink: #e6e2d8;
  --ink-muted: #9a9488;
  --accent: #d4a574;
  --accent-soft: rgba(212, 165, 116, 0.14);
  --line: rgba(230, 226, 216, 0.12);
  --panel: #1e222c;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

[data-theme="jade"] {
  --bg: #dfe8e4;
  --bg-soft: #eef4f1;
  --ink: #1a2b26;
  --ink-muted: #5a6f68;
  --accent: #2f6b5a;
  --accent-soft: rgba(47, 107, 90, 0.14);
  --line: rgba(26, 43, 38, 0.12);
  --panel: #f4f8f6;
  --shadow: 0 18px 48px rgba(26, 43, 38, 0.12);
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 90% 60% at 10% -10%, var(--accent-soft), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 0%, rgba(90, 110, 130, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  line-height: 1.5;
  transition: background 0.35s ease, color 0.35s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: 0;
}

[data-theme="ink"] body::before,
html[data-theme="ink"]::before {
  mix-blend-mode: soft-light;
  opacity: 0.2;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.view { min-height: 100vh; }

/* Author `display` must not override the HTML hidden attribute */
[hidden] {
  display: none !important;
}

.back {
  display: inline-block;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  transition: color 0.15s;
}
.back:hover { color: var(--accent); }

/* —— Library —— */
.view-library {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.library-hero {
  margin-bottom: 2rem;
  animation: rise 0.7s ease both;
}

.brand {
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.28em;
  color: var(--accent);
  margin: 0 0 0.75rem;
}

.library-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  font-weight: 400;
  margin: 0 0 0.75rem;
  letter-spacing: 0.06em;
  line-height: 1.15;
}

.library-sub {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 36ch;
}

.dropzone {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  min-height: 0;
  padding: 1.1rem 1.25rem;
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  animation: rise 0.7s ease 0.08s both;
  box-shadow: none;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: none;
}

.dropzone.uploading {
  opacity: 0.65;
  pointer-events: none;
}

.library-status {
  margin: 0.85rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
  min-height: 1.2em;
  letter-spacing: 0.04em;
}

/* —— Hot 玄幻 —— */
.hot-section {
  margin-top: 2rem;
  animation: rise 0.7s ease 0.12s both;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line);
}

.section-toggle {
  width: 100%;
  margin: 0;
  padding: 0.15rem 0 0.55rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  transition: opacity 0.15s;
}

.section-toggle:hover {
  opacity: 0.85;
}

.section-toggle-main {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.section-chevron {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 1.5px solid var(--ink-muted);
  border-bottom: 1.5px solid var(--ink-muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex: 0 0 auto;
  margin-top: -0.15rem;
}

.hot-section.is-collapsed .section-chevron {
  transform: rotate(-45deg);
  margin-top: 0.1rem;
}

.section-head h2,
.section-toggle h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  margin: 0;
}

.section-count {
  font-size: 0.78rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.section-note {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.hot-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.28s ease, opacity 0.2s ease, margin 0.2s ease;
  opacity: 1;
  margin-top: 0.9rem;
}

.hot-body > .hot-grid {
  overflow: hidden;
  min-height: 0;
}

.hot-section.is-collapsed .hot-body {
  grid-template-rows: 0fr;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

.hot-section.is-collapsed .section-toggle {
  margin-bottom: 0;
}

.hot-section.is-collapsed .section-note {
  display: none;
}

.hot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.hot-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  padding: 1rem 1.05rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--accent-soft) 55%, var(--panel)), var(--panel));
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  animation: rise 0.5s ease both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.hot-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(28, 26, 23, 0.08);
}

.hot-card-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.hot-heat {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.hot-title {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.hot-author {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.hot-blurb {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  line-height: 1.55;
  color: color-mix(in srgb, var(--ink) 78%, var(--ink-muted));
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hot-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-muted);
}

.hot-cta {
  margin-top: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.rank-block {
  margin-top: 1.35rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
}

.rank-block h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.1em;
}

.rank-note {
  margin: 0.4rem 0 0.75rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.rank-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rank-chip {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 7.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, color 0.15s;
}

.rank-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.rank-chip strong {
  font-size: 0.88rem;
  font-weight: 600;
}

.rank-chip span,
.rank-chip em {
  font-size: 0.72rem;
  font-style: normal;
  color: var(--ink-muted);
}

@media (max-width: 560px) {
  .hot-grid {
    grid-template-columns: 1fr;
  }
  .section-toggle {
    flex-direction: column;
    align-items: flex-start;
  }
  .section-note {
    margin-left: 1rem;
  }
}

.dropzone-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  font-size: 1.15rem;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0;
  margin: 0;
}

.dropzone-copy {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.dropzone-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.dropzone-hint {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.library-list {
  margin-top: 1.75rem;
  animation: rise 0.7s ease 0.16s both;
}

.library-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line);
}

.library-list h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  margin: 0;
  color: var(--ink);
}

.library-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.book-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.book-item:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--panel) 70%, var(--accent-soft));
  transform: none;
}

.book-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.book-item-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-item-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.book-item-delete {
  flex: 0 0 auto;
  align-self: center;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--ink-muted);
  background: transparent;
  border: none;
  border-radius: 3px;
  padding: 0.35rem 0.45rem;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, color 0.15s;
}
.book-item:hover .book-item-delete {
  opacity: 1;
}
.book-item-delete:hover {
  color: var(--accent);
  border-color: transparent;
}

/* —— Reader —— */
.view-reader {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr minmax(0, var(--reader-max)) 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.reader-bar-left,
.reader-bar-right {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.reader-bar-left { justify-self: start; }
.reader-bar-right { justify-self: end; }

.reader-book-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-muted);
}

.icon-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.listen-bar {
  position: sticky;
  top: 3.35rem;
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.listen-btn {
  font-family: inherit;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
}
.listen-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.listen-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

#listen-status {
  font-size: 0.82rem;
  font-weight: 600;
}

.listen-chapter {
  font-size: 0.72rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.listen-rate {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
  flex: 0 0 auto;
}

.listen-rate select {
  font-family: inherit;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg-soft);
  color: var(--ink);
  padding: 0.25rem 0.35rem;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  cursor: pointer;
}
.switch input {
  accent-color: var(--accent);
}

.reader-body {
  flex: 1;
  width: min(100% - 2rem, var(--reader-max));
  margin: 0 auto;
  padding: 2.25rem 0 3rem;
  animation: fade 0.45s ease both;
}

.chapter-title {
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 4vw, 1.85rem);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-align: center;
  margin: 0 0 2rem;
  color: var(--accent);
  line-height: 1.4;
}

.chapter-content {
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
  text-align: justify;
  word-break: break-word;
}

.chapter-content p {
  margin: 0 0 1.15em;
  text-indent: 2em;
}

.chapter-content p.empty {
  text-indent: 0;
  min-height: 0.6em;
}

.chapter-title .tts-unit,
.chapter-content .tts-unit {
  transition: color 0.2s ease, background-color 0.2s ease;
  border-radius: 2px;
}

.tts-unit.tts-read {
  color: #1f8a4c;
}

[data-theme="ink"] .tts-unit.tts-read {
  color: #5dcea0;
}

[data-theme="jade"] .tts-unit.tts-read {
  color: #1f7a5a;
}

.tts-unit.tts-current {
  color: var(--accent);
  background: var(--accent-soft);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.chapter-title.tts-listening {
  transition: color 0.2s ease;
}

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: min(100% - 2rem, var(--reader-max));
  margin: 0 auto 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.nav-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chapter-progress {
  font-size: 0.82rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

/* TOC */
.toc-panel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: min(320px, 88vw);
  height: 100%;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 0.28s ease;
  display: flex;
  flex-direction: column;
}
.toc-panel.open { transform: translateX(0); }

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(20, 18, 14, 0.35);
  backdrop-filter: blur(2px);
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.toc-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: 0.12em;
}

.toc-list {
  overflow-y: auto;
  padding: 0.5rem 0 1.5rem;
  flex: 1;
}

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  padding: 0.65rem 1.1rem;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.toc-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.toc-item.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* Settings */
.settings-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 18, 14, 0.35);
  backdrop-filter: blur(2px);
  animation: fade 0.2s ease both;
}

.settings-inner {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 1.25rem 1.35rem 1.5rem;
  box-shadow: var(--shadow);
  animation: slide-up 0.28s ease both;
}

.settings-inner h3 {
  margin: 0 0 1.1rem;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.12em;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.theme-picks,
.font-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.theme-btn,
.font-controls button {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 2.2rem;
  height: 2.2rem;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  cursor: pointer;
}
.theme-btn[data-theme="paper"] { background: #f3efe6; color: #8b3a2a; }
.theme-btn[data-theme="ink"] { background: #1a1d26; color: #d4a574; }
.theme-btn[data-theme="jade"] { background: #dfe8e4; color: #2f6b5a; }
.theme-btn.active,
.theme-btn:hover,
.font-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.theme-btn[data-theme="ink"].active,
.theme-btn[data-theme="ink"]:hover {
  color: #d4a574;
  border-color: #d4a574;
}

#font-size-label,
#line-height-label {
  min-width: 2.4rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.settings-close {
  width: 100%;
  margin-top: 0.5rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 640px) {
  .reader-bar {
    grid-template-columns: auto 1fr auto;
  }
  .reader-body {
    padding-top: 1.5rem;
  }
  .chapter-content {
    text-align: left;
  }
}
