:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #6b7280;
  --muted: #6b7280;
  --line: #eef0f3;
  --accent: #e11d2e;
  --accent-soft: #fff1f2;
  --danger: #e11d2e;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --font: "Plus Jakarta Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-shell[hidden], .login-wrap[hidden] { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 320px at 50% 0%, rgba(225, 29, 46, 0.08), transparent 60%),
    var(--bg);
}
.login-panel {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.login-panel h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
}
.login-panel > p {
  margin: 0 0 8px;
  color: var(--muted);
}
.login-brand { margin-bottom: 4px; }
.login-panel .field { width: 100%; min-width: 0; }
.login-panel .btn-primary { width: 100%; margin-top: 4px; }
.field {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
}
.err {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
}
.err[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: var(--ink);
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.brand em {
  font-style: normal;
  color: var(--accent);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.nav-btn:hover { background: var(--bg-soft); color: var(--ink); }
.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-btn.soon { opacity: 0.45; }

.search-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-box input {
  width: min(220px, 28vw);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}
.search-box button, .btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #c41222; border-color: #c41222; }
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.platform-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 20px 0;
}
.platform-chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--ink-soft);
}
.platform-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.main {
  flex: 1;
  padding: 16px 20px 40px;
  background: var(--bg);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 18px;
  align-items: end;
}
.filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.filters input, .filters select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  min-width: 140px;
}

.search-head {
  margin: 4px 0 14px;
  font-size: 13px;
  color: var(--ink-soft);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 1100px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .book-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .search-box input { width: 140px; }
}

.book-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.book-card:hover { border-color: #f0a8b6; }

.cover {
  width: 84px;
  height: 112px;
  border-radius: 6px;
  background: var(--bg-soft);
  overflow: hidden;
}
.cover img, .rank-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  line-height: 1.35;
}
.book-card .intro {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink-soft);
}
.tag.push-yes { background: var(--accent-soft); color: var(--accent); }
.tag.push-no { background: #fff4e8; color: #b86a1c; }

.rank-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 1000px) {
  .rank-board { grid-template-columns: 1fr; }
}
.rank-col {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.rank-col h3 { margin: 0 0 4px; font-size: 16px; }
.rank-col .updated {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--ink-soft);
}
.rank-item {
  display: grid;
  grid-template-columns: 28px 48px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.rank-item:hover { background: var(--bg-soft); }
.rank-no { font-weight: 700; color: var(--accent); }
.rank-thumb {
  width: 48px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-soft);
}
.rank-item .title { font-size: 14px; font-weight: 600; }
.rank-item .cat { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

.detail-crumb {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}
.detail-crumb .back-link { margin: 0; }

/* 上：封面 | 原信息 | AI */
.detail-top {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 12px;
  margin-bottom: 14px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .detail-top { grid-template-columns: 1fr 1fr; }
  .poster-col { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 820px) {
  .detail-top { grid-template-columns: 1fr; }
}

.poster-col,
.origin-col,
.ai-zone {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 260px;
}

.poster-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.poster-col .cover {
  width: 120px;
  height: 160px;
}
.poster-col .btn {
  width: 100%;
  text-align: center;
}

.origin-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.origin-col .col-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.origin-col .col-hd h3 {
  margin: 0;
  font-size: 15px;
}
.origin-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  word-break: break-word;
}
.origin-meta {
  font-size: 13px;
  color: var(--ink);
  line-height: 1.5;
}
.origin-block {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 150px;
}
.origin-block strong {
  color: var(--ink);
  font-weight: 600;
}
.genre-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.genre-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.3;
}

.ai-zone {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.ai-zone-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.ai-zone-hd h3 {
  margin: 0;
  font-size: 15px;
  flex: 1;
}
.ai-zone-tip {
  margin: 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.ai-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1;
}
@media (max-width: 720px) {
  .ai-grid { grid-template-columns: 1fr; }
}
.ai-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 110px;
}
.ai-card-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.ai-card-hd .title {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
}
.ai-card-hd .acts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ai-link {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
  font-size: 12px;
}
.ai-link:disabled {
  color: #c4c4c4;
  cursor: not-allowed;
}
.ai-link.locked { color: #999; }
.ai-card-bd {
  padding: 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 96px;
  flex: 1;
  min-height: 64px;
}
.ai-card-bd:empty::before {
  content: "点击生成获取内容";
  color: #bbb;
}

/* 章节选择条 */
.read-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.read-toolbar label {
  font-size: 13px;
  color: var(--ink-soft);
}
.read-toolbar select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 200px;
  background: #fff;
}
.hl-switch {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}
.hl-switch button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}
.hl-switch button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dual {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
@media (max-width: 900px) {
  .dual { grid-template-columns: 1fr; }
}
.pane {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.pane-hd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  font-weight: 600;
}
.pane-bd {
  padding: 14px;
  overflow: auto;
  max-height: 420px;
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 14px;
  color: var(--ink);
  flex: 1;
}

.download-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.download-box h3 {
  margin: 0;
  font-size: 14px;
  margin-right: auto;
}
.download-box .btn.ghost {
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.empty, .loading {
  padding: 40px;
  text-align: center;
  color: var(--ink-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.back-link {
  display: inline-flex;
  margin-bottom: 12px;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
}
