/* ============================================================
   星海 · 番茄小说 v3 完全重写
   深空玻璃拟态 · 流动星尘 · 精致交互
   ============================================================ */

:root {
  --bg-deep: #02040a;
  --bg-mid: #060b18;
  --bg-card: rgba(15, 22, 45, 0.6);
  --bg-card-hover: rgba(22, 32, 60, 0.8);
  --border: rgba(100, 150, 255, 0.1);
  --border-hover: rgba(120, 170, 255, 0.25);
  --text: #eaf0ff;
  --text-2: #8fa3c8;
  --text-3: #556888;
  --accent: #5b9dff;
  --accent-light: #8ec2ff;
  --accent-glow: rgba(91, 157, 255, 0.3);
  --accent-grad: linear-gradient(135deg, #4a8eff 0%, #7ab8ff 50%, #a5d4ff 100%);
  --gold: #f5c96a;
  --danger: #ff6b7a;
  --success: #5ce0a0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  position: relative;
}

.hidden { display: none !important; }

a { color: var(--accent-light); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent); }

.container { max-width: 980px; margin: 0 auto; padding: 0 20px; }

/* ---------- 星空背景 ---------- */
.starfield {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(ellipse 90% 50% at 50% -5%, rgba(74, 142, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 85% 75%, rgba(122, 184, 255, 0.06), transparent),
    radial-gradient(ellipse 50% 30% at 10% 60%, rgba(91, 157, 255, 0.05), transparent),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 50%, var(--bg-deep) 100%);
}
.stars, .stars2, .stars3 {
  position: absolute; inset: 0; background-repeat: repeat;
}
.stars {
  background-image:
    radial-gradient(1px 1px at 20px 30px, #fff, transparent),
    radial-gradient(1px 1px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90px 40px, #fff, transparent),
    radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 160px 120px, #fff, transparent);
  background-size: 200px 200px;
  animation: drift 120s linear infinite;
}
.stars2 {
  background-image:
    radial-gradient(1.5px 1.5px at 50px 100px, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 150px 50px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 250px 150px, rgba(255,255,255,0.7), transparent);
  background-size: 300px 300px;
  animation: drift 180s linear infinite;
}
.stars3 {
  background-image:
    radial-gradient(2px 2px at 100px 200px, rgba(142,194,255,0.7), transparent),
    radial-gradient(1.5px 1.5px at 300px 100px, #fff, transparent);
  background-size: 400px 400px;
  animation: drift 240s linear infinite;
}
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(-200px); } }

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(2, 4, 10, 0.75);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; height: 62px; gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-size: 17px; font-weight: 700;
}
.brand em { font-style: normal; color: var(--accent); }
.brand-icon {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-grad); border-radius: 10px; color: #fff;
  box-shadow: 0 2px 14px var(--accent-glow);
}
.brand-icon svg { width: 19px; height: 19px; }
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav a {
  padding: 8px 18px; border-radius: 9px;
  color: var(--text-2); font-size: 14px; font-weight: 500;
  transition: all 0.2s;
}
.topnav a:hover { color: var(--text); background: var(--bg-card); }
.topnav a.active {
  color: var(--accent); background: var(--bg-card);
  box-shadow: inset 0 0 0 1px var(--border-hover);
}

/* ---------- 用户区域 ---------- */
.user-area { position: relative; margin-left: auto; }
.user-trigger {
  width: 40px; height: 40px; border: 1px solid var(--border);
  border-radius: 50%; background: var(--bg-card); color: var(--text-2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.25s;
}
.user-trigger:hover {
  color: var(--text); border-color: var(--border-hover);
  background: var(--bg-card-hover); transform: scale(1.05);
}
.user-trigger svg { width: 19px; height: 19px; }
.user-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0;
  min-width: 250px; padding: 12px;
  background: rgba(12, 18, 38, 0.92);
  border: 1px solid var(--border-hover);
  border-radius: 16px; backdrop-filter: blur(24px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  z-index: 200;
  animation: dropdownIn 0.2s ease;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.user-dropdown-inner { font-size: 14px; }
.user-loading { color: var(--text-3); text-align: center; padding: 18px 0; }

/* ---------- 用户下拉内容 ---------- */
.ud-header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 10px 16px;
}
.ud-header.ud-guest { opacity: 0.85; }
.ud-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: #fff;
  font-size: 20px; font-weight: 700;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.ud-info { flex: 1; min-width: 0; }
.ud-name {
  font-size: 15px; font-weight: 700; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ud-email {
  font-size: 12px; color: var(--text-2); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ud-divider { height: 1px; background: var(--border); margin: 8px 0; }
.ud-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 10px; border-radius: 10px;
  color: var(--text-2); font-size: 13.5px; cursor: pointer;
  transition: all 0.18s; text-decoration: none;
}
.ud-item:hover { background: var(--bg-card); color: var(--text); }
.ud-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.ud-item.ud-login { color: var(--accent); font-weight: 600; }
.ud-item.ud-logout { color: var(--danger); }
.ud-item.ud-logout:hover { background: rgba(255,107,122,0.1); }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 52px 0 26px; }
.hero-title {
  font-size: 40px; font-weight: 800; margin-bottom: 12px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 0%, var(--accent-light) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-sub { color: var(--text-2); font-size: 15px; margin-bottom: 28px; }

/* ---------- 搜索框 ---------- */
.search-box {
  display: flex; gap: 12px; max-width: 600px; margin: 0 auto 22px;
  padding: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; backdrop-filter: blur(12px);
  transition: all 0.25s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 0 24px rgba(91,157,255,0.12);
}
.search-box input {
  flex: 1; padding: 12px 16px; background: transparent; border: none;
  color: var(--text); font-size: 15px; outline: none;
}
.search-box input::placeholder { color: var(--text-3); }
.search-box button {
  padding: 12px 26px; border: none; border-radius: 11px;
  background: var(--accent-grad); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: all 0.2s; box-shadow: 0 3px 14px var(--accent-glow);
  white-space: nowrap;
}
.search-box button:hover { transform: translateY(-1px); box-shadow: 0 5px 20px var(--accent-glow); }
.search-box button:active { transform: translateY(0); }
.search-box button svg { width: 17px; height: 17px; }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 28px;
}
.tab {
  padding: 9px 22px; border: 1px solid var(--border);
  border-radius: 22px; background: transparent; color: var(--text-2);
  font-size: 13.5px; font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.tab:hover { color: var(--text); border-color: var(--border-hover); }
.tab.active {
  color: var(--accent); background: var(--bg-card);
  border-color: var(--border-hover); font-weight: 600;
}

/* ---------- 内容区 ---------- */
.content { min-height: 240px; padding-bottom: 40px; }

/* ---------- 加载 / 空状态 ---------- */
.loading-state {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 70px 20px; color: var(--text-3); font-size: 14px;
}
.loading-state .spin {
  width: 36px; height: 36px; color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  padding: 50px 20px; text-align: center; color: var(--text-3); font-size: 14px;
  background: var(--bg-card); border: 1px dashed var(--border);
  border-radius: 14px;
}

/* ---------- 书籍网格 ---------- */
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 18px;
}
.book-card {
  padding: 16px; border-radius: 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; transition: all 0.25s;
  backdrop-filter: blur(8px);
}
.book-card:hover {
  border-color: var(--border-hover); background: var(--bg-card-hover);
  transform: translateY(-3px); box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.book-cover {
  width: 100%; aspect-ratio: 3/4; border-radius: 10px;
  background: var(--bg-mid); object-fit: cover; margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.book-info { min-width: 0; }
.book-name {
  font-size: 14.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 5px;
}
.book-author { font-size: 12px; color: var(--accent-light); margin-bottom: 5px; }
.book-abstract {
  font-size: 11.5px; color: var(--text-3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 书籍详情 ---------- */
.book-detail {
  padding: 24px; border-radius: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  backdrop-filter: blur(16px); margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.detail-header { display: flex; gap: 24px; margin-bottom: 22px; }
.detail-cover {
  width: 130px; height: 174px; border-radius: 12px;
  background: var(--bg-mid); object-fit: cover; flex-shrink: 0;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.detail-info { flex: 1; min-width: 0; }
.detail-title { font-size: 24px; font-weight: 800; color: var(--text); margin-bottom: 10px; }
.detail-author { font-size: 15px; color: var(--accent-light); margin-bottom: 14px; }
.detail-abstract {
  font-size: 13.5px; color: var(--text-2); line-height: 1.8; margin-bottom: 18px;
}
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- 章节列表 ---------- */
.chapter-section { margin-top: 24px; }
.chapter-section h3 {
  font-size: 17px; font-weight: 700; color: var(--text);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}
.chapter-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}
.chapter-item {
  padding: 11px 16px; border-radius: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; cursor: pointer;
  transition: all 0.2s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chapter-item:hover {
  color: var(--text); border-color: var(--accent);
  background: var(--bg-card-hover);
}

/* ---------- 下载相关 ---------- */
.dl-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; border-radius: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  margin-bottom: 10px;
}
.dl-hint { font-size: 13.5px; color: var(--text-2); flex: 1; min-width: 120px; }
.dl-server-opt {
  padding: 7px 14px; border-radius: 7px;
  background: var(--bg-mid); color: var(--text-2);
  font-size: 12px; border: 1px solid var(--border);
}
.dl-status { font-size: 12px; color: var(--accent-light); white-space: nowrap; font-weight: 500; }
.dl-progress {
  width: 100%; height: 7px; border-radius: 4px;
  background: var(--bg-mid); overflow: hidden; margin-top: 4px;
}
.dl-progress-fill {
  height: 100%; border-radius: 4px;
  background: var(--accent-grad); transition: width 0.3s;
}

/* ---------- 下载任务列表 ---------- */
.task-item {
  padding: 16px; border-radius: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  margin-bottom: 12px; transition: all 0.2s;
}
.task-item:hover { border-color: var(--border-hover); }
.task-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.task-book {
  font-size: 15px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-status {
  padding: 4px 12px; border-radius: 7px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; flex-shrink: 0;
}
.task-status.pending { background: rgba(245,201,106,0.15); color: var(--gold); }
.task-status.running { background: rgba(91,157,255,0.15); color: var(--accent); }
.task-status.done { background: rgba(92,224,160,0.15); color: var(--success); }
.task-status.failed { background: rgba(255,107,122,0.15); color: var(--danger); }
.task-meta { font-size: 12.5px; color: var(--text-3); margin-top: 5px; }
.task-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
  padding: 9px 20px; border: 1px solid var(--border-hover);
  border-radius: 9px; background: var(--bg-card); color: var(--text-2);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg-card-hover); }
.btn-primary {
  padding: 11px 24px; border: none; border-radius: 10px;
  background: var(--accent-grad); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; box-shadow: 0 3px 14px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 5px 20px var(--accent-glow); }
.btn-block { width: 100%; justify-content: center; }

/* ---------- 阅读器 ---------- */
.reader {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg-deep); display: none; flex-direction: column;
}
/* 显隐由 JS 切 .active 类（openReader/closeReader），这里必须对应 active，
   早年写成 :not(.hidden) 导致阅读器默认就铺满全屏、拦截整个页面的点击 */
.reader.active { display: flex; }
.reader-header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: rgba(2, 4, 10, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.reader-title {
  flex: 1; font-size: 15px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reader-nav { display: flex; gap: 10px; }
.reader-btn {
  padding: 8px 18px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-card); color: var(--text-2);
  font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.reader-btn:hover { color: var(--text); border-color: var(--border-hover); background: var(--bg-card-hover); }
.reader-content {
  flex: 1; overflow-y: auto; padding: 36px 28px;
  font-size: 16px; line-height: 2.1; color: var(--text);
  max-width: 760px; margin: 0 auto; width: 100%;
}
.reader-content p { margin-bottom: 18px; text-indent: 2em; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 500px; max-height: 82vh;
  background: rgba(12, 18, 38, 0.95);
  border: 1px solid var(--border-hover);
  border-radius: 18px; backdrop-filter: blur(24px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); }
.modal-close {
  width: 34px; height: 34px; border: none; border-radius: 9px;
  background: transparent; color: var(--text-3); font-size: 18px;
  cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-card); color: var(--text); }
.modal-body {
  flex: 1; overflow-y: auto; padding: 22px;
  font-size: 14px; color: var(--text-2); line-height: 1.7;
}
.modal-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 24px; border-radius: 11px;
  background: rgba(12, 18, 38, 0.95);
  border: 1px solid var(--border-hover);
  color: var(--text); font-size: 14px; font-weight: 500;
  backdrop-filter: blur(20px); box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
}
.toast.success { border-color: rgba(92, 224, 160, 0.4); color: var(--success); }
.toast.error { border-color: rgba(255, 107, 122, 0.4); color: var(--danger); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .hero { padding: 36px 0 20px; }
  .hero-title { font-size: 28px; }
  .hero-sub { font-size: 13px; }
  .search-box { flex-direction: column; padding: 12px; }
  .search-box button { width: 100%; justify-content: center; }
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .detail-header { flex-direction: column; align-items: center; text-align: center; }
  .detail-cover { width: 110px; height: 147px; }
  .chapter-list { grid-template-columns: 1fr; }
  .topnav a { padding: 7px 12px; font-size: 13px; }
  .brand { font-size: 15px; }
  .brand-icon { width: 32px; height: 32px; }
  .reader-content { padding: 24px 18px; font-size: 15px; }
  .reader-nav { display: none; }
  .user-dropdown { right: -8px; min-width: 230px; }
  .task-actions .btn { flex: 1; justify-content: center; }
  .dl-row { flex-direction: column; align-items: flex-start; }
}
