/* ============================================================
   KxComic 样式表 — 日夜主题 / 安全区适配 / 重新设计
   ============================================================ */

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

/* ---------- 主题变量（默认浅色） ---------- */
:root {
  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #eef0fa;
  --bg-subtle: #ebedf6;
  --bg-header: rgba(255,255,255,0.82);
  --text: #1b1b2e;
  --text-secondary: #5a5a78;
  --text-muted: #9090ac;
  --accent: #6c5ce7;
  --accent-light: #8b7cf0;
  --accent-soft: rgba(108,92,231,0.12);
  --border: #e4e6f1;
  --shadow: 0 6px 24px rgba(30,30,60,0.08);
  --shadow-sm: 0 2px 10px rgba(30,30,60,0.06);
  --danger: #ff5d6c;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --transition: .2s ease;
  --header-h: 60px;
}
/* 跟随系统：夜间 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b16;
    --bg-elevated: #14142a;
    --bg-card: #16162e;
    --bg-card-hover: #21214a;
    --bg-subtle: #1a1a33;
    --bg-header: rgba(11,11,22,0.82);
    --text: #e9e9f2;
    --text-secondary: #9d9dc0;
    --text-muted: #6a6a8c;
    --accent: #7c6cf0;
    --accent-light: #a99bff;
    --accent-soft: rgba(124,108,240,0.18);
    --border: #28284c;
    --shadow: 0 6px 24px rgba(0,0,0,0.4);
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.3);
  }
}
/* 手动：夜间 */
:root[data-theme="dark"] {
  --bg: #0b0b16;
  --bg-elevated: #14142a;
  --bg-card: #16162e;
  --bg-card-hover: #21214a;
  --bg-subtle: #1a1a33;
  --bg-header: rgba(11,11,22,0.82);
  --text: #e9e9f2;
  --text-secondary: #9d9dc0;
  --text-muted: #6a6a8c;
  --accent: #7c6cf0;
  --accent-light: #a99bff;
  --accent-soft: rgba(124,108,240,0.18);
  --border: #28284c;
  --shadow: 0 6px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 10px rgba(0,0,0,0.3);
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 头部 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px); /* 避开刘海/灵动岛 */
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; flex-shrink: 0; }
.logo-icon { font-size: 22px; }
.logo-text .accent, .accent { color: var(--accent); }
.main-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 8px 14px; border-radius: var(--radius-sm); color: var(--text-secondary);
  font-size: 15px; transition: var(--transition);
}
.nav-link:hover { color: var(--text); background: var(--bg-subtle); }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }
.search-box {
  margin-left: auto; display: flex; align-items: center;
  background: var(--bg-subtle); border: 1px solid transparent;
  border-radius: 22px; padding: 4px 4px 4px 14px; min-width: 0; max-width: 280px; flex: 1;
  transition: var(--transition);
}
.search-box:focus-within { border-color: var(--accent); background: var(--bg-elevated); }
.search-box input {
  border: none; outline: none; background: transparent; color: var(--text);
  font-size: 14px; width: 100%; min-width: 0;
}
.search-btn { border: none; background: transparent; font-size: 16px; padding: 6px 8px; border-radius: 50%; }
.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--bg-elevated); border-radius: 50%;
  font-size: 17px; transition: var(--transition);
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.mobile-menu-btn { display: none; }
.mobile-nav { display: none; }

/* ---------- 通用容器 ---------- */
#mainContent { max-width: 1200px; margin: 0 auto; padding: 16px; }
.section { margin-bottom: 28px; }
.section-header, .page-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.section-header h2, .page-title-row h2 { font-size: 19px; font-weight: 700; }
.view-all { color: var(--accent); font-size: 14px; }

/* ---------- 按钮 ---------- */
.btn-primary, .btn-secondary, .btn-fav, .btn-small {
  border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
  padding: 11px 20px; transition: var(--transition);
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-light)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-fav { background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border); }
.btn-fav.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn-small { padding: 8px 14px; font-size: 14px; background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border); }
.btn-small:disabled { opacity: .4; }
.btn-text { background: none; border: none; color: var(--accent); font-size: 13px; padding: 2px 0; }

/* ---------- Hero ---------- */
.hero {
  border-radius: var(--radius-lg); padding: 44px 28px; margin-bottom: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff; box-shadow: var(--shadow);
}
.hero-content h1 { font-size: 28px; margin-bottom: 8px; }
.hero-content p { opacity: .92; margin-bottom: 18px; }
.hero .btn-primary { background: #fff; color: var(--accent); }

/* ---------- 分类卡 ---------- */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 12px; }
.category-card, .category-tabs .tab-btn { cursor: pointer; }
.category-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; text-align: center; font-weight: 600; transition: var(--transition); box-shadow: var(--shadow-sm);
}
.category-card:hover { border-color: var(--accent); transform: translateY(-2px); color: var(--accent); }
.category-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab-btn {
  padding: 7px 16px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-secondary); font-size: 14px; transition: var(--transition);
}
.tab-btn:hover { border-color: var(--accent); }
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 漫画网格 / 卡片 ---------- */
.comic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 16px; }
.comic-card { cursor: pointer; transition: var(--transition); }
.comic-card:hover { transform: translateY(-3px); }
.comic-card-cover {
  position: relative; aspect-ratio: 3/4; border-radius: var(--radius); overflow: hidden;
  background: var(--bg-subtle); box-shadow: var(--shadow-sm);
}
.comic-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.comic-card:hover .comic-card-cover { box-shadow: var(--shadow); }
.comic-card-badge {
  position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; color: #fff; backdrop-filter: blur(4px);
}
.badge-ongoing { background: rgba(108,92,231,0.85); }
.badge-completed { background: rgba(0,200,150,0.85); }
.comic-card-views {
  position: absolute; bottom: 8px; right: 8px; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; color: #fff; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
}
.comic-card-title {
  margin-top: 8px; font-size: 14px; font-weight: 500; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- 排序 / 分页 ---------- */
.sort-row { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.sort-select {
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text); font-size: 14px;
}
.chapter-tools { display: flex; align-items: center; gap: 12px; }
.chapter-tools #chapterCount { color: var(--text-muted) !important; font-size: 13px; }
.sort-toggle {
  background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 15px; font-size: 13px; white-space: nowrap; transition: var(--transition);
}
.sort-toggle:hover { border-color: var(--accent); color: var(--accent); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
.page-btn {
  min-width: 38px; height: 38px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text); font-size: 14px; transition: var(--transition);
}
.page-btn:hover { border-color: var(--accent); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:disabled { opacity: .4; }

/* ---------- 详情页 ---------- */
.detail-container { max-width: 900px; margin: 0 auto; }
.back-btn { background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 8px 16px; font-size: 14px; margin-bottom: 16px; }
.detail-content { display: flex; gap: 22px; margin-bottom: 26px; }
.detail-cover { position: relative; width: 220px; flex-shrink: 0; }
.detail-cover img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--bg-subtle); }
.detail-rating { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.6); color: #ffd76e; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.detail-info { flex: 1; min-width: 0; }
.detail-info h1 { font-size: 24px; margin-bottom: 12px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 14px; }
.meta-item { font-size: 13px; color: var(--text-secondary); }
.meta-item strong { color: var(--text); font-weight: 600; }
.detail-desc { color: var(--text-secondary); font-size: 14px; line-height: 1.8; margin-bottom: 18px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- 章节列表 ---------- */
.chapter-section { margin-top: 8px; }
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 10px; }
.chapter-link {
  display: block; padding: 11px 14px; border-radius: var(--radius-sm); background: var(--bg-card);
  border: 1px solid var(--border); font-size: 13px; color: var(--text); transition: var(--transition);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chapter-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 个人中心 ---------- */
.profile-section { max-width: 760px; margin: 0 auto; }
.auth-box, .user-box, .settings-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-secondary); font-weight: 600; }
.auth-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 15px; outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-submit { margin-top: 4px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.auth-hint { color: var(--text-muted); font-size: 13px; margin-top: 14px; text-align: center; }

.user-head { display: flex; align-items: center; gap: 14px; }
.user-avatar {
  width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-light)); color: #fff; font-size: 22px; font-weight: 700;
}
.user-name { font-size: 18px; font-weight: 700; }
.profile-tabs { display: flex; gap: 8px; margin: 20px 0 16px; }
.profile-tab { flex: 1; padding: 9px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-secondary); font-weight: 600; }
.profile-tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: var(--radius-sm);
  background: var(--bg-subtle); cursor: pointer; transition: var(--transition);
}
.history-item:hover { background: var(--bg-card-hover); }
.history-item img { width: 46px; height: 62px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--bg-card); }
.history-item .hi-info { flex: 1; min-width: 0; }
.history-item .hi-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .hi-sub { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .hi-del { background: none; border: none; color: var(--text-muted); font-size: 18px; padding: 4px 8px; }

.settings-title { font-weight: 700; margin-bottom: 12px; }
.theme-options { display: flex; gap: 8px; }
.theme-opt { flex: 1; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-secondary); font-size: 14px; }
.theme-opt.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 状态 ---------- */
.loading { text-align: center; color: var(--text-muted); padding: 30px; font-size: 14px; }
.empty-state, .error-state { text-align: center; color: var(--text-muted); padding: 50px 20px; }
.error-state h2 { color: var(--text); margin-bottom: 12px; }
.error-state .btn-primary, .empty-state .btn-primary { margin-top: 16px; display: inline-block; }

/* ---------- 页脚 ---------- */
.site-footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: 28px 16px; border-top: 1px solid var(--border); margin-top: 20px; }

/* ---------- 底部导航（手机） ---------- */
.bottom-nav { display: none; }
@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    background: var(--bg-header); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 0 7px; color: var(--text-muted); font-size: 11px;
  }
  .bn-icon { font-size: 20px; line-height: 1; }
  .bn-item.active { color: var(--accent); }
  body { padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- 响应式（手机） ---------- */
@media (max-width: 768px) {
  .main-nav { display: none; }
  .header-inner { gap: 10px; }
  .logo-text { display: none; }
  .search-box { max-width: none; }
  .hero { padding: 32px 20px; }
  .hero-content h1 { font-size: 22px; }
  .comic-grid { grid-template-columns: repeat(auto-fill, minmax(108px,1fr)); gap: 12px; }
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(100px,1fr)); }
  .chapter-grid { grid-template-columns: repeat(auto-fill, minmax(110px,1fr)); }
  .detail-content { flex-direction: column; align-items: center; text-align: center; }
  .detail-cover { width: 160px; }
  .detail-meta { justify-content: center; }
  .detail-actions { justify-content: center; }
  #mainContent { padding: 14px 12px; }
}

/* ============================================================
   阅读器（始终深色，独立于主题）+ 全屏沉浸
   ============================================================ */
.reader-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: rgba(10,10,22,0.95); color: #fff; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.reader-header h3 { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-nav-btns { display: flex; gap: 8px; }
.reader-content { max-width: 820px; margin: 0 auto; padding: 16px; }
.reader-content img { width: 100%; margin-bottom: 6px; border-radius: 4px; display: block; }
.reader-footer { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 22px; background: #0c0c18; color:#fff; }

/* 进入阅读：隐藏全站导航，纯黑滚动阅读区 */
body.reader-immersive { background: #000; }
body.reader-immersive .site-header,
body.reader-immersive .site-footer,
body.reader-immersive .bottom-nav { display: none !important; }
body.reader-immersive .reader-header { display: none !important; }
body.reader-immersive .reader-nav-btns,
body.reader-immersive .reader-footer { display: none !important; }
body.reader-immersive { padding-bottom: 0 !important; }
body.reader-immersive .reader-content { max-width: 100%; margin: 0; padding: 0; padding-top: env(safe-area-inset-top, 0px); }
body.reader-immersive .reader-content img { display: block; width: 100%; margin: 0; border-radius: 0; vertical-align: top; }
@media (min-width: 769px) { body.reader-immersive .reader-content { max-width: 820px; margin: 0 auto; } }

/* 隐藏章节分隔标题（不再显示“第几话”） */
.reader-chapter-label { display: none !important; }
.reader-empty { text-align: center; color: rgba(255,255,255,0.6); padding: 40px 16px; }

/* 底部加载：仅一个小转圈，无文字 */
.reader-sentinel {
  color: transparent; min-height: 40px; display: flex; align-items: center; justify-content: center;
  padding: 22px 16px calc(env(safe-area-inset-bottom,0px) + 28px);
}
.reader-spinner { display: none; }
.reader-sentinel.loading .reader-spinner {
  display: inline-block; width: 22px; height: 22px;
  border: 2px solid rgba(255,255,255,0.22); border-top-color: rgba(255,255,255,0.85);
  border-radius: 50%; animation: kxspin 0.8s linear infinite;
}
@keyframes kxspin { to { transform: rotate(360deg); } }

/* ============================================================
   全屏遮罩（横屏提示 / iOS 引导）— 深色
   ============================================================ */
.kx-overlay {
  display: none; position: fixed; inset: 0; z-index: 99999;
  background: #0a0a16; color: #fff; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: calc(env(safe-area-inset-top,0px) + 24px) 28px calc(env(safe-area-inset-bottom,0px) + 24px);
}
.kx-overlay-box { max-width: 440px; }
.kx-rotate-icon { font-size: 64px; margin-bottom: 14px; display: inline-block; animation: kxrotate 2.2s ease-in-out infinite; }
@keyframes kxrotate { 0%,100%{transform:rotate(0)} 50%{transform:rotate(-90deg)} }
.kx-overlay-logo { font-size: 56px; margin-bottom: 10px; }
.kx-overlay-title { font-size: 21px; font-weight: 700; margin: 8px 0; }
.kx-overlay-sub { font-size: 14px; color: rgba(255,255,255,0.72); line-height: 1.7; margin-bottom: 18px; }
.kx-ios-steps { text-align: left; display: inline-block; padding-left: 22px; margin: 0; line-height: 2; font-size: 15px; color: rgba(255,255,255,0.92); }
.kx-ios-steps b { color: #b79dff; }
.kx-ios-arrow {
  position: absolute; bottom: calc(env(safe-area-inset-bottom,0px) + 12px); left: 50%;
  font-size: 46px; line-height: 1; color: #b79dff; animation: kxbounce 1.3s ease-in-out infinite;
}
@keyframes kxbounce { 0%,100%{transform:translate(-50%,0)} 50%{transform:translate(-50%,12px)} }
@media (orientation: landscape) and (max-height: 520px) { #rotateOverlay { display: flex; } }
#iosGate { z-index: 100000; }
