/* ============================================================
   responsive.css - All media queries, touch optimizations, safe-area
   ============================================================ */
/* ============================================================
   RESPONSIVE - Comprehensive 5-breakpoint system
   Breakpoints: 1200 / 992 / 768 / 640 / 480
   ============================================================ */
/* --- 1200px: Large desktop tweaks --- */
@media (max-width: 1200px) {
  .container { max-width: 100%; padding: 20px 20px; }
  .novel-hero-inner { max-width: 100%; padding: 24px 20px; }
  .novel-content { max-width: 100%; padding: 0 20px; }
  .footer-main { max-width: 100%; padding: 32px 20px; }
}

/* --- 992px: Small desktop / large tablet --- */
@media (max-width: 992px) {
  .container { padding: 16px; }
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .layout { grid-template-columns: 1fr; }
  .novel-content { grid-template-columns: 1fr; padding: 0 16px; }
  .footer-main { grid-template-columns: 1fr 1fr; gap: 20px; }
  .header-nav > a span.nav-label { display: none; }
  .header-nav > a { padding: 8px 10px; }
  .header-search input { width: 140px; }
  .carousel-slide { height: 260px; padding: 24px; }
  .carousel-slide .slide-cover { width: 140px; height: 200px; }
  .slide-title { font-size: 24px; }
  .slide-info { max-width: 58%; }
  .novel-hero-inner { padding: 20px 16px; gap: 20px; }
  .novel-cover-wrap, .novel-cover-wrap img { width: 150px; height: 200px; }
  .novel-title { font-size: 22px; }
  .chapter-list { grid-template-columns: repeat(2, 1fr); }
  .search-hero { padding: 32px 0 24px; }
  .search-hero h2 { font-size: 22px; }
}

/* --- 768px: Tablet (NEW) --- */
@media (max-width: 768px) {
  .container { padding: 14px; }
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .header-inner { gap: 8px; }
  .header-logo { font-size: 17px; }
  .header-logo .logo-mark { width: 28px; height: 28px; }
  .header-nav { gap: 2px; }
  .header-nav > a { padding: 8px 8px; font-size: 13px; }
  .header-search { flex: 1; max-width: 200px; }
  .header-search form { width: 100%; }
  .header-search input { width: 100%; min-width: 0; font-size: 13px; }
  .header-search .search-btn { width: 34px; }
  .icon-btn { width: 34px; height: 34px; }
  .carousel-slide { height: 220px; padding: 20px; }
  .carousel-slide .slide-cover { width: 110px; height: 160px; right: 14px; }
  .slide-title { font-size: 20px; }
  .slide-desc { font-size: 13px; -webkit-line-clamp: 2; }
  .slide-info { max-width: 60%; }
  .slide-btn { padding: 7px 18px; font-size: 13px; }
  .section-title { font-size: 17px; }
  .novel-hero-inner { flex-direction: column; align-items: center; text-align: center; gap: 18px; padding: 18px 14px; }
  .novel-cover-wrap, .novel-cover-wrap img { width: 130px; height: 174px; }
  .novel-title { font-size: 20px; }
  .novel-meta-row { justify-content: center; gap: 12px; font-size: 13px; }
  .novel-stats { gap: 8px; }
  .stat-card { padding: 8px 6px; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 11px; }
  .novel-tags { justify-content: center; }
  .novel-actions { justify-content: center; }
  .novel-content { padding: 0 14px; }
  .chapter-list { grid-template-columns: repeat(2, 1fr); gap: 4px 12px; }
  .footer-main { grid-template-columns: 1fr 1fr; padding: 24px 14px; gap: 18px; }
  .result-card { gap: 12px; padding: 12px; }
  .result-cv { width: 60px; height: 82px; }
  .result-title { font-size: 15px; }
  .result-desc { font-size: 12px; }
  .rank-item { gap: 10px; padding: 9px 0; }
  .rank-val { font-size: 11px; }
  .tabs a, .tabs button { padding: 8px 12px; font-size: 13px; }
  .chips { gap: 6px; margin-bottom: 14px; }
  .chip { padding: 5px 12px; font-size: 12px; }
  .reader { padding: 20px 16px 80px; }
  .reader-top h1 { font-size: 20px; }
  .reader-content { font-size: 18px; }
}

/* --- 640px: Large phone --- */
@media (max-width: 640px) {
  .container { padding: 12px; }
  .header-nav { display: none; }
  .mobile-menu-btn { display: flex; }
  .header-search { flex: 1; }
  .header-search form { width: 100%; }
  .header-search input { width: 100%; min-width: 0; }
  .header-actions { gap: 6px; margin-left: auto; padding-right: 4px; }
  .header-logo { font-size: 16px; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .book-title { font-size: 13px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; min-height: 36px; }
  .book-author { font-size: 11px; }
  .book-meta { font-size: 11px; }
  .carousel-slide { height: 200px; padding: 16px; }
  .carousel-slide .slide-cover { width: 90px; height: 130px; right: 12px; }
  .slide-title { font-size: 18px; }
  .slide-desc { -webkit-line-clamp: 2; font-size: 12px; }
  .slide-info { max-width: 62%; }
  .slide-tag { font-size: 11px; padding: 2px 8px; }
  .slide-btn { padding: 6px 16px; font-size: 12px; }
  .carousel-arrow { width: 32px; height: 32px; font-size: 14px; }
  .novel-hero-inner { flex-direction: column; align-items: center; text-align: center; gap: 16px; padding: 16px 12px; }
  .novel-cover-wrap, .novel-cover-wrap img { width: 120px; height: 160px; }
  .novel-title { font-size: 19px; margin-bottom: 10px; }
  .novel-meta-row { justify-content: center; gap: 10px; font-size: 12px; flex-wrap: wrap; }
  .novel-stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat-card { padding: 8px 4px; }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 10px; }
  .novel-tags { justify-content: center; gap: 5px; }
  .tag { font-size: 11px; padding: 2px 8px; }
  .novel-actions { justify-content: center; gap: 8px; }
  .novel-actions .btn { padding: 8px 16px; font-size: 13px; }
  .novel-content { padding: 0 12px; margin-top: 14px; }
  .chapter-section { padding: 12px; }
  .chapter-list { grid-template-columns: repeat(2, 1fr); gap: 4px 10px; }
  .chapter-item, .ch-item { padding: 6px 6px; font-size: 12px; }
  .ch-wc { font-size: 10px; }
  .volume-tab { padding: 4px 10px; font-size: 11px; }
  .footer-main { grid-template-columns: 1fr; padding: 24px 12px; gap: 16px; }
  .footer-brand p { font-size: 12px; }
  .footer-col ul li { margin-bottom: 6px; }
  .footer-col ul a { font-size: 12px; }
  .reader { padding: 16px 14px 90px; }
  .reader-top { margin-bottom: 18px; padding-bottom: 16px; }
  .reader-top h1 { font-size: 19px; }
  .reader-top .sub { font-size: 12px; }
  .reader-content { font-size: 17px; line-height: 1.85; }
  .reader-nav { gap: 8px; margin-top: 24px; padding-top: 16px; }
  .reader-nav .btn { flex: 1; padding: 10px 8px; font-size: 13px; }
  .rd-bar .tb { padding: 2px 10px; font-size: 10px; }
  .rd-set { width: 94vw; padding: 14px 16px; bottom: 56px; }
  .set-row { gap: 8px; margin-bottom: 10px; }
  .ctls button { min-width: 30px; height: 30px; font-size: 13px; }
  .search-hero { padding: 28px 0 20px; }
  .search-hero h2 { font-size: 20px; }
  .search-hero .sub { font-size: 13px; }
  .search-hero input { padding: 10px 14px; font-size: 14px; }
  .search-hero button { padding: 0 20px; font-size: 14px; }
  .results-header { font-size: 13px; flex-wrap: wrap; gap: 6px; }
  .result-card { gap: 10px; padding: 10px; }
  .result-cv { width: 56px; height: 76px; }
  .result-title { font-size: 14px; }
  .result-author { font-size: 12px; }
  .result-desc { font-size: 12px; -webkit-line-clamp: 2; }
  .result-meta { gap: 8px; font-size: 11px; }
  .rank-item { gap: 8px; padding: 8px 0; }
  .rank-num { width: 22px; height: 22px; font-size: 12px; }
  .rank-title { font-size: 13px; }
  .rank-meta { font-size: 11px; }
  .rank-val { font-size: 11px; }
  .tabs { gap: 2px; }
  .tabs a, .tabs button { padding: 8px 10px; font-size: 12px; }
  .section-head { margin-bottom: 12px; }
  .section-title { font-size: 16px; }
  .section-more { font-size: 12px; }
  .side-card-head { padding: 10px 14px; font-size: 14px; }
  .side-card-body { padding: 10px 14px; }
  .pagination a, .pagination span { padding: 6px 10px; font-size: 12px; }
  .page-btn { padding: 6px 14px; font-size: 12px; }
  .page-info { font-size: 12px; }
  .empty, .no-results { padding: 40px 16px; }
}

/* --- 480px: Small phone (NEW) --- */
@media (max-width: 480px) {
  .container { padding: 10px; }
  .header-inner { padding: 0 10px; }
  .header-logo { font-size: 15px; gap: 6px; }
  .header-logo .logo-mark { width: 26px; height: 26px; }
  .header-search { flex: 1; }
  .header-search form { width: 100%; }
  .header-search input { width: 100%; min-width: 0; font-size: 12px; padding: 6px 10px; }
  .header-search .search-btn { width: 30px; flex-shrink: 0; }
  .header-actions { gap: 4px; margin-left: auto; padding-right: 2px; }
  .icon-btn { width: 32px; height: 32px; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .book-cover { border-radius: 4px; }
  .book-tag { font-size: 10px; padding: 1px 5px; }
  .book-body { padding: 6px 1px 0; }
  .book-title { font-size: 12px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; min-height: 32px; }
  .book-author { font-size: 10px; margin-top: 2px; }
  .book-meta { font-size: 10px; margin-top: 3px; }
  .carousel-slide { height: 180px; padding: 14px; }
  .carousel-slide .slide-cover { width: 75px; height: 110px; right: 10px; }
  .slide-title { font-size: 16px; margin-bottom: 6px; }
  .slide-desc { font-size: 11px; -webkit-line-clamp: 2; margin-bottom: 10px; }
  .slide-info { max-width: 64%; }
  .slide-tag { font-size: 10px; padding: 2px 6px; margin-bottom: 8px; }
  .slide-btn { padding: 5px 14px; font-size: 11px; }
  .carousel-dots { bottom: 10px; gap: 6px; }
  .carousel-dots button { width: 18px; height: 3px; }
  .novel-hero-inner { padding: 14px 10px; gap: 14px; }
  .novel-cover-wrap, .novel-cover-wrap img { width: 100px; height: 134px; }
  .novel-title { font-size: 17px; }
  .novel-meta-row { font-size: 11px; gap: 8px; }
  .novel-stats { gap: 4px; }
  .stat-card { padding: 6px 3px; }
  .stat-value { font-size: 13px; }
  .stat-label { font-size: 9px; }
  .novel-content { padding: 0 10px; }
  .chapter-section { padding: 10px; }
  .chapter-list { grid-template-columns: 1fr; gap: 2px; }
  .chapter-item, .ch-item { padding: 8px 6px; font-size: 13px; }
  .result-card { flex-direction: column; gap: 10px; padding: 10px; }
  .result-cv { width: 80px; height: 108px; margin: 0 auto; }
  .result-info { text-align: center; }
  .result-title { font-size: 14px; }
  .result-meta { justify-content: center; }
  .rank-val { display: none; }
  .rank-item:hover .rank-val { display: block; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tabs a, .tabs button { flex-shrink: 0; padding: 8px 12px; }
  .chips { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .chip { flex-shrink: 0; }
  .reader { padding: 14px 12px 85px; }
  .reader-top h1 { font-size: 17px; }
  .reader-content { font-size: 16px; line-height: 1.8; }
  .reader-nav .btn { font-size: 12px; padding: 9px 6px; }
  .rd-bar .tb { padding: 2px 8px; font-size: 9px; }
  .rd-set { width: 96vw; padding: 12px; }
  .footer-main { padding: 20px 10px; gap: 14px; }
  .footer-bottom { font-size: 11px; padding: 12px; }
  .search-hero { padding: 24px 0 18px; }
  .search-hero h2 { font-size: 18px; }
  .search-hero input { padding: 9px 12px; font-size: 13px; }
  .search-hero button { padding: 0 16px; font-size: 13px; }
  .mobile-nav-panel { width: 260px; padding: 16px; }
  .mobile-nav-links a { padding: 10px 6px; font-size: 14px; }
}

/* --- Touch device optimizations --- */
@media (hover: none) and (pointer: coarse) {
  .book-card:hover .book-cover img { transform: none; }
  .carousel-arrow { display: none; }
  a, button { -webkit-tap-highlight-color: transparent; }
}

/* --- Safe area for notched phones --- */
@supports (padding: max(0px)) {
  .site-header { padding-left: max(0px, env(safe-area-inset-left)); padding-right: max(0px, env(safe-area-inset-right)); }
  .container { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
}

@media (max-width: 768px) {
  .filter-label {
    width: 36px;
    font-size: 12px;
  }
  .filter-row .chip {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 12px;
  }
}

/* ============================================================
   MOBILE FOOTER REDESIGN - highest priority
   ============================================================ */
@media (max-width: 768px) {
  .site-footer .footer-main {
    grid-template-columns: 1fr !important;
    padding: 20px 14px 12px !important;
    gap: 16px !important;
  }
  .site-footer .footer-brand {
    text-align: center !important;
  }
  .site-footer .footer-logo {
    justify-content: center !important;
    font-size: 16px !important;
    margin-bottom: 6px !important;
  }
  .site-footer .footer-brand p {
    font-size: 11px !important;
    line-height: 1.6 !important;
    max-width: 260px !important;
    margin: 0 auto !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }
  /* Nav columns: compact horizontal tag layout */
  .site-footer .footer-col {
    text-align: center !important;
    border-top: 1px solid var(--border) !important;
    padding-top: 12px !important;
  }
  .site-footer .footer-col:first-of-type {
    border-top: none !important;
    padding-top: 0 !important;
  }
  .site-footer .footer-col h4 {
    font-size: 12px !important;
    margin-bottom: 8px !important;
    color: var(--text-2) !important;
    font-weight: 600 !important;
    display: inline-block !important;
    padding: 0 10px !important;
    position: relative !important;
  }
  .site-footer .footer-col h4::before,
  .site-footer .footer-col h4::after {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    width: 16px !important;
    height: 1px !important;
    background: var(--border) !important;
  }
  .site-footer .footer-col h4::before { right: 100% !important; }
  .site-footer .footer-col h4::after { left: 100% !important; }
  .site-footer .footer-col ul {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 4px 12px !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
  }
  .site-footer .footer-col ul li {
    margin-bottom: 0 !important;
    display: inline !important;
  }
  .site-footer .footer-col ul a {
    font-size: 11px !important;
    color: var(--text-3) !important;
    padding: 2px 0 !important;
    white-space: nowrap !important;
    display: inline !important;
  }
  .site-footer .footer-col ul a:active {
    color: var(--primary) !important;
  }
  .site-footer .footer-bottom {
    padding: 10px 14px !important;
    font-size: 10px !important;
    line-height: 1.6 !important;
  }
}

@media (max-width: 480px) {
  .site-footer .footer-main {
    padding: 16px 12px 10px !important;
    gap: 12px !important;
  }
  .site-footer .footer-brand p {
    font-size: 10px !important;
    max-width: 220px !important;
  }
  .site-footer .footer-logo {
    font-size: 15px !important;
  }
  .site-footer .footer-col {
    padding-top: 10px !important;
  }
  .site-footer .footer-col h4 {
    font-size: 11px !important;
    margin-bottom: 6px !important;
  }
  .site-footer .footer-col ul {
    gap: 3px 10px !important;
  }
  .site-footer .footer-col ul a {
    font-size: 10px !important;
  }
  .site-footer .footer-bottom {
    padding: 8px 12px !important;
    font-size: 9px !important;
  }
}

/* Mobile responsive */
@media (max-width: 640px) {
  .modal-overlay { padding: 12px; }
  .modal-box { max-height: 85vh; border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 12px 16px; overflow-y: auto; max-height: calc(85vh - 56px); }
  .character-card { gap: 10px; padding: 10px 0; }
  .character-avatar { width: 38px; height: 38px; font-size: 16px; }
  .character-name { font-size: 13px; }
  .character-identity { font-size: 11px; }
  .character-desc { font-size: 11px; }
}

/* --- Fix 1: novel-stats 在640px以下正确使用grid布局 ---
   基础样式是 display:flex，但640px断点只设了grid-template-columns
   导致grid不生效，4个统计卡片挤在一行 */
@media (max-width: 640px) {
  .novel-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
}

/* --- Fix 2: 480px以下统计卡片改为2x2网格，避免4列过窄 --- */
@media (max-width: 480px) {
  .novel-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

/* --- Fix 3: 移动端header搜索框解除max-width:200px限制 ---
   768px断点设置了 max-width:200px，在640px以下仍生效
   导致搜索框不能全宽伸展，右侧按钮与搜索框之间出现大段空白 */
@media (max-width: 640px) {
  .header-search {
    max-width: none !important;
    flex: 1 1 auto;
    min-width: 0;
  }
  .header-search input {
    min-width: 0;
  }
  /* 确保右侧按钮组真正贴右 */
  .header-actions {
    margin-left: auto !important;
    flex-shrink: 0;
  }
}

/* --- Fix 4: 弹窗在小屏使用92vw最大宽度，防止溢出 --- */
@media (max-width: 640px) {
  .modal-box {
    max-width: 92vw;
    width: 100%;
  }
}

/* --- Fix 5: tabs在平板/手机支持横向滚动，防止溢出 --- */
@media (max-width: 768px) {
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a, .tabs button {
    flex-shrink: 0;
  }
}

/* --- Fix 7: 小屏filter-row改为纵向布局，label独占一行 ---
   375px下36px的label挤压chips空间，改为纵向更合理 */
@media (max-width: 480px) {
  .filter-row {
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
  }
  .filter-label {
    width: auto;
    text-align: left;
    padding-top: 0;
    font-size: 12px;
    color: var(--text-3);
    font-weight: 600;
  }
  .filter-row .chips {
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

@media (max-width: 640px) {
  .reader {
    padding-bottom: 100px;
  }
}

@media (max-width: 480px) {
  .reader {
    padding-bottom: 95px;
  }
}

/* --- Fix 12: 平板768px下novel-stats保持flex但紧凑 --- */
@media (min-width: 641px) and (max-width: 992px) {
  .novel-stats {
    display: flex;
    gap: 10px;
  }
}

/* --- Fix 13: 小屏搜索结果卡片文字不溢出 --- */
@media (max-width: 480px) {
  .result-title {
    font-size: 14px;
    word-break: break-word;
  }
  .result-desc {
    text-align: left;
    -webkit-line-clamp: 3;
  }
}

/* --- Fix 14: 确保header在移动端不换行 --- */
@media (max-width: 640px) {
  .site-header { height: var(--header-h); }
  .header-inner {
    flex-wrap: nowrap;
    gap: 6px;
  }
  .header-logo span:last-child {
    white-space: nowrap;
  }
}

/* --- Fix 15: 小说详情页操作按钮在小屏可滚动 --- */
@media (max-width: 480px) {
  .novel-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }
  .novel-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    white-space: nowrap;
  }
}

/* --- Fix 16: 章节目录在小屏单行不换行 --- */
@media (max-width: 480px) {
  .chapter-list {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .ch-item, .chapter-item {
    font-size: 13px;
    padding: 8px 6px;
  }
}

/* --- Fix 19: 分类页chips在移动端横向滚动时隐藏滚动条 --- */
@media (max-width: 480px) {
  .chips {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .chips::-webkit-scrollbar { display: none; }
}