:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --border: #e8ebf0;
  --primary: #1f6feb;
  --primary-soft: #e8f1ff;
  --accent: #e8553f;
  --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 6px 18px rgba(20, 30, 60, .05);
  --radius: 12px;
  --header-h: 54px;
  --channel-h: 46px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 顶部导航 ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, #1f6feb, #2a8a6b);
  color: #fff;
  box-shadow: 0 2px 10px rgba(20, 40, 90, .18);
}
.topbar-inner {
  max-width: 800px;
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; opacity: .92; }
.cat-nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-tab {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, transform .08s;
}
.cat-tab:hover { background: rgba(255, 255, 255, .28); }
.cat-tab:active { transform: scale(.96); }
.cat-tab.active { background: #fff; color: var(--primary); }

/* ===== 频道条 ===== */
.channel-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--channel-h);
  display: flex;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 12px;
  gap: 8px;
}
.channel-bar::-webkit-scrollbar { display: none; }
.channel-bar:empty { display: none; }

.channel-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 480px;
  padding: 8px 36px 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23646a73' d='M6 8.5L1.5 4h9z'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.channel-select:hover { border-color: var(--primary); }
.channel-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 235, .15); }
.channel-select option { font-weight: 500; }

/* ===== 频道页网格 ===== */
.channel-body {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.ch-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .08s;
  font-family: inherit;
}
.ch-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(31, 111, 235, .12);
}
.ch-card:active { transform: scale(.98); }
.ch-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.ch-tid {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  flex-shrink: 0;
}
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ===== 主区域 ===== */
.main {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 14px 80px;
}
.view[hidden] { display: none; }

.list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
  margin: 2px 2px 12px;
}
.list-meta .col-name { color: var(--text); font-weight: 600; }

.list-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform .08s, box-shadow .15s, border-color .15s;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.card:hover {
  border-color: #c9d6ef;
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.card:active { transform: translateY(0) scale(.995); }
.card .idx {
  flex: 0 0 auto;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card .ttl {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ===== 分页 ===== */
.pagination {
  margin: 22px 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}
.pager-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.pager-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pager-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-btn:disabled { opacity: .4; cursor: not-allowed; }
.pager-info { color: var(--text-3); font-size: 13px; padding: 0 6px; }
.pager-jump {
  width: 64px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 9px;
  text-align: center;
  font-size: 14px;
}
.pager-jump:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

/* ===== 文章页 ===== */
.article-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 8px;
  box-shadow: var(--shadow);
}
.article-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.back-btn {
  appearance: none;
  border: 0;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
}
.back-btn:hover { background: #d8e7ff; }
.article-title {
  margin: 0 0 14px;
  font-size: 22px;
  line-height: 1.4;
  font-weight: 700;
  word-break: break-word;
  text-align: center;
}
.article-title::after {
  content: "";
  display: block;
  margin: 12px auto 0;
  width: 60%;
  max-width: 320px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  flex: 1 1 auto;
}
.tag {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f0f2f5;
  color: var(--text-2);
}
.tag.link { background: var(--primary-soft); color: var(--primary); cursor: pointer; }
.article-body {
  font-size: 16px;
  line-height: 1.8;
  overflow: hidden;
  word-break: break-word;
}
.article-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10px auto;
  border-radius: 8px;
}
.article-body p { margin: 10px 0; }
/* 禁用手机浏览器对正文中数字串自动识别为电话/邮箱链接 */
.article-body a[href^="tel:"],
.article-body a[href^="mailto:"] {
  color: inherit;
  text-decoration: none;
  cursor: text;
  pointer-events: none;
}
.article-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 22px 0 14px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color .15s, background .15s;
}
.nav-link:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.nav-link:disabled { opacity: .45; cursor: not-allowed; }
.nav-link .nav-label { font-size: 12px; color: var(--text-3); flex: 0 0 auto; }
.nav-link .nav-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
}

/* ===== 空状态 / 错误 ===== */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-2);
}
.empty .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 8px; color: var(--text); font-size: 18px; }
.empty p { margin: 4px 0; font-size: 14px; }
.empty code {
  background: #eef1f6;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 13px;
}
.empty .retry-btn {
  margin-top: 16px;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  padding: 9px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}
.empty .retry-btn:hover { background: #1858c4; }

/* ===== 底部栏目 ===== */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 20px;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom, 0));
}
.footer-inner {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}
.footer-text {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-2);
}
.footer-copy {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

/* ===== 回到顶部 ===== */
.to-top {
  position: fixed;
  right: 18px;
  bottom: 22px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(31, 111, 235, .4);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}
.to-top:hover { background: #1858c4; }

/* ===== 加载层 ===== */
.loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(244, 246, 250, .72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading[hidden] { display: none; }
.loading-card {
  background: var(--surface);
  padding: 22px 30px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.loading-text { color: var(--text-2); font-size: 14px; }
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #e3e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 视图切换动画 */
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  :root { --header-h: 50px; }
  .brand { font-size: 16px; }
  .cat-tab { font-size: 14px; padding: 6px 13px; }
  .main { padding: 12px 10px 80px; }
  .channel-body { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .ch-card { padding: 12px 14px; }
  .ch-name { font-size: 13px; }
  .article-wrap { padding: 14px 14px 6px; }
  .article-title { font-size: 19px; }
}

/* ===== 列表页返回按钮 ===== */
.list-back {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 10px;
}
.list-back:hover { border-color: var(--primary); color: var(--primary); }
