:root {
  --bg: #0f1218;
  --card: #171c26;
  --border: #232b3a;
  --text: #e6eaf2;
  --muted: #8a93a6;
  --accent: #ff5f4e;
  --up: #ff6b57;
  --down: #3ecf8e;
  --hover: rgba(255,255,255,.03);
  color-scheme: dark;
}

/* 浅色主题：data-theme="light" 强制浅色；"auto" 跟随系统 */
:root[data-theme="light"] {
  --bg: #f2f4f8;
  --card: #ffffff;
  --border: #e2e7f0;
  --text: #1c2333;
  --muted: #6b7486;
  --accent: #ff5f4e;
  --up: #e04a36;
  --down: #149e68;
  --hover: rgba(20,32,56,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f2f4f8;
    --card: #ffffff;
    --border: #e2e7f0;
    --text: #1c2333;
    --muted: #6b7486;
    --accent: #ff5f4e;
    --up: #e04a36;
    --down: #149e68;
    --hover: rgba(20,32,56,.05);
    color-scheme: light;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
}

header {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; }
.logo { font-size: 22px; }

nav#rank-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
#rank-tabs button {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 5px 14px; cursor: pointer; font-size: 13px;
  transition: all .15s;
}
#rank-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#rank-tabs button:hover:not(.active) { color: var(--text); border-color: var(--muted); }

.meta { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; gap: 14px; align-items: center; }
.theme-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s;
}
.theme-btn:hover { border-color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--down); display: inline-block; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

main { max-width: 1280px; margin: 20px auto; padding: 0 20px; display: flex; flex-direction: column; gap: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .row2 { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; flex-wrap: wrap; row-gap: 6px; }
.card h2 { font-size: 15px; font-weight: 600; }
.legend-hint { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
td.pos { font-weight: 700; font-size: 15px; width: 70px; }
.mv-up { color: var(--up); font-size: 11px; }
.mv-down { color: var(--down); font-size: 11px; }
.delta-pos { font-weight: 600; }
.delta-pos.plus { color: var(--up); }
.delta-pos.minus { color: var(--down); }
.book-title { font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { color: var(--muted); font-size: 12px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-cell { color: var(--muted); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }

.range-btns button {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 3px 10px; cursor: pointer; font-size: 12px; margin-left: 4px;
}
.range-btns button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chart { width: 100%; }
.chart.tall { height: 360px; }
.chart.mid { height: 300px; }

ul#event-list { list-style: none; max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
#event-list li {
  background: var(--hover); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; line-height: 1.5;
}
#event-list li time { color: var(--muted); font-size: 11px; display: block; }
.badge { display: inline-block; border-radius: 4px; font-size: 11px; padding: 0 6px; margin-right: 6px; }
.badge.new   { background: rgba(62,207,142,.15); color: var(--down); }
.badge.drop  { background: rgba(138,147,166,.15); color: var(--muted); }
.badge.move  { background: rgba(255,95,78,.15); color: var(--up); }
.badge.readers { background: rgba(255,193,7,.12); color: #ffc107; }

.hidden { display: none; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 32px; }

/* ---------- 移动端适配 ---------- */
.book-meta-sm { display: none; }

@media (max-width: 640px) {
  header {
    flex-direction: column; align-items: stretch;
    gap: 8px; padding: 10px 14px;
    position: static;   /* 堆叠后高度大，取消吸顶避免占用小屏空间 */
  }
  .brand { font-size: 16px; }
  .brand small { display: none; }
  .logo { font-size: 19px; }

  /* 榜单 Tab：单行横向滑动，不换行 */
  nav#rank-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #rank-tabs::-webkit-scrollbar { display: none; }
  #rank-tabs button { flex: 0 0 auto; padding: 6px 14px; }

  .meta { margin-left: 0; justify-content: center; gap: 10px; }

  main { margin-top: 12px; padding: 0 10px; gap: 12px; }
  .card { padding: 12px; border-radius: 10px; }
  .legend-hint { display: none; }   /* 说明文字在窄屏下省空间，桌面端保留 */

  /* 表格压缩为四列：排名 / 书名 / 在读 / Δ在读；作者与状态并入书名副行 */
  #rank-table th:nth-child(3), #rank-table td:nth-child(3),
  #rank-table th:nth-child(6), #rank-table td:nth-child(6),
  #rank-table th:nth-child(7), #rank-table td:nth-child(7) { display: none; }
  th, td { padding: 8px 4px; }
  td.pos { width: auto; min-width: 34px; font-size: 13px; white-space: nowrap; }
  .book-title, .book-sub {
    max-width: 100%; white-space: normal;
    word-break: break-word; line-height: 1.35;
  }
  .book-meta-sm { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
  .readers-cell { font-weight: 600; white-space: nowrap; text-align: right; }

  .range-btns button { padding: 5px 9px; }
  .chart.tall { height: 280px; }
  .chart.mid { height: 240px; }
  footer { padding: 16px 10px 26px; }
}
