/* ============================================
   响应式样式 - 适配移动端、平板和PC端
   参考 h5-web_demo 和 noveliax.com 的响应式策略
   ============================================ */

/* 
 * 核心策略：
 * 1. 移动端：限制容器宽度 max-width: 480px，居中显示
 * 2. PC端（>= 768px）：取消宽度限制，铺满浏览器，使用flex自适应列数
 * 3. 保持移动端完全不受影响
 */

/* 移动端默认：不限制body/html宽度，让各页面容器自己控制 */
body,
html {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
}

/* 首页容器 - 移动端限制宽度（在 index.html 内联样式中定义） */
/* .home_page_shell 的样式已在 index.html 中定义，此处不重复 */

/* ============================================
   其他页面容器 - 移动端默认限制宽度
   ============================================ */
.book-detail-container,
.book-list-container,
.category-container,
.category_container,
.personal_center,
.search-container,
.library_container,
.topup-container,
.svip-container {
    max-width: 480px;
    margin: 0 auto;
}

/* ============================================
   PC端适配 (>= 768px) - 铺满浏览器
   ============================================ */
@media screen and (min-width: 768px) {
    /* 取消宽度限制，让内容铺满浏览器 */
    body,
    html {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* 首页容器 - PC端铺满 */
    .home_page_shell {
        max-width: none !important;
        width: 100% !important;
        padding: 0 20px;
    }
    
    .home_page_shell .home_container {
        max-width: none !important;
        width: 100% !important;
    }
    
    /* 头部 - PC端铺满 */
    .home_page_shell .header-box {
        max-width: 100% !important;
        width: 100% !important;
        left: 0 !important;
        transform: none !important;
    }
    
    /* 底部标签栏 - PC端铺满 */
    .home_page_shell .tabBar_box,
    .tabBar_box {
        max-width: 100% !important;
        left: 0 !important;
        transform: none !important;
        width: 100% !important;
    }
    
    /* Popular/Featured 横向滑动区域 - PC端改为网格布局 */
    .list_item_box--shelf {
        display: flex !important;
        flex-wrap: wrap !important;
        overflow-x: visible !important;
        gap: 20px !important;
        padding: 0 !important;
    }
    
    .list_item_box--shelf .book-item {
        flex: 0 0 calc((100% - 3 * 20px) / 4) !important;
        width: calc((100% - 3 * 20px) / 4) !important;
        max-width: none !important;
    }
    
    .list_item_box--shelf .book-item .right p {
        font-size: 16px !important;
        line-height: 1.3 !important;
    }
    
    /* New Releases 书籍列表 - PC端改为2列布局 */
    .book-box-3--nr {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 16px !important;
        justify-content: space-between !important;
    }
    
    .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 16px) / 2) !important;
        width: calc((100% - 16px) / 2) !important;
        margin-bottom: 0 !important;
    }
    
    /* 书籍详情页 - PC端铺满 */
    .book-detail-container {
        max-width: none !important;
        width: 100% !important;
        padding: 0 20px;
    }
    
    .book-detail-header {
        max-width: none !important;
        width: 100% !important;
        left: 0 !important;
        transform: none !important;
    }
    
    .book-read-section {
        max-width: none !important;
        width: 100% !important;
        left: 0 !important;
        transform: none !important;
    }
    
    /* 书籍列表页 - PC端铺满 */
    .book-list-container {
        max-width: 100%;
        padding: 0 20px;
    }
    
    .book-list-container .header-box {
        max-width: 100%;
        left: 0;
        transform: none;
    }
    
    .book-list-container .book-box-3--nr {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
    }
    
    .book-list-container .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 5 * 12px) / 6) !important;
        width: calc((100% - 5 * 12px) / 6) !important;
    }
    
    /* 分类页面 - PC端铺满 */
    .category-container,
    .category_container {
        max-width: 100%;
        padding: 0 20px;
    }
    
    .category_container .header-box {
        max-width: 100%;
        left: 0;
        transform: none;
    }
    
    /* 个人中心页 - PC端铺满 */
    .personal_center {
        max-width: none !important;
        width: 100% !important;
        padding: 0 20px;
    }
    
    /* 搜索页面 - PC端铺满 */
    .search-container {
        max-width: 100%;
        padding: 0 20px;
    }
    
    /* Library页面 - PC端铺满 */
    .library_container {
        max-width: 100%;
        padding: 0 20px;
    }
    
    /* 充值页面 - PC端铺满 */
    .topup-container,
    .svip-container {
        max-width: none !important;
        width: 100% !important;
        padding: 0 20px;
    }
}

/* ============================================
   大屏幕优化 (>= 1024px)
   ============================================ */
@media screen and (min-width: 1024px) {
    /* Popular/Featured - 大屏显示5列 */
    .list_item_box--shelf .book-item {
        flex: 0 0 calc((100% - 4 * 20px) / 5) !important;
        width: calc((100% - 4 * 20px) / 5) !important;
    }
    
    /* New Releases - 大屏显示3列 */
    .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 2 * 16px) / 3) !important;
        width: calc((100% - 2 * 16px) / 3) !important;
    }
    
    .book-list-container .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 2 * 16px) / 3) !important;
        width: calc((100% - 2 * 16px) / 3) !important;
    }
}

/* ============================================
   超大屏幕优化 (>= 1440px)
   ============================================ */
@media screen and (min-width: 1440px) {
    /* Popular/Featured - 超大屏显示6列 */
    .list_item_box--shelf .book-item {
        flex: 0 0 calc((100% - 5 * 20px) / 6) !important;
        width: calc((100% - 5 * 20px) / 6) !important;
    }
    
    /* New Releases - 超大屏显示4列 */
    .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 3 * 16px) / 4) !important;
        width: calc((100% - 3 * 16px) / 4) !important;
    }
    
    .book-list-container .book-box-3--nr .book-item {
        flex: 0 0 calc((100% - 3 * 16px) / 4) !important;
        width: calc((100% - 3 * 16px) / 4) !important;
    }
}


/* 阅读器页面特殊处理 - 桌面端保持单列布局 */
@media screen and (min-width: 768px) {
    /* 确保 body 和 html 背景色铺满，消除白条 */
    body.reader-body,
    html.reader-html {
        background-color: var(--bg-color, #F6F6F6) !important;
        width: 100vw !important;
        max-width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow-x: hidden;
    }
    
    /* 确保阅读器容器居中但背景铺满 */
    .reader_container {
        max-width: 800px; /* 阅读器在桌面端保持较窄的宽度，便于阅读 */
        margin: 0 auto;
        width: 100%;
    }
    
    .reader_content {
        max-width: 800px;
        margin: 0 auto;
        padding-left: 40px;
        padding-right: 40px;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* 修复头部布局 - 确保标题和按钮正确显示 */
    .reader_header {
        max-width: 800px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0 16px !important;
        box-sizing: border-box !important;
    }
    
    /* 确保左侧标题区域正确显示 */
    .reader_header_left {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow: visible !important;
        max-width: none !important;
    }
    
    /* 确保标题文字可见 */
    .reader_header_left p {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
        width: auto !important;
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* 确保返回按钮不压缩 */
    .reader_header_left img {
        flex-shrink: 0 !important;
        width: 24px !important;
        height: 24px !important;
    }
    
    /* 确保右侧按钮正确显示在最右边 */
    .reader_header_right {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        margin-left: auto !important;
        width: auto !important;
        min-width: 24px !important;
        position: relative !important;
        z-index: 1 !important;
    }
    
    .reader_header_right img {
        flex-shrink: 0 !important;
        width: 24px !important;
        height: 24px !important;
        display: block !important;
    }
    
    /* 确保底部菜单和卡片也居中 */
    .menu_bottom {
        max-width: 800px;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 100% !important;
    }
    
    /* 确保底部菜单遮罩层铺满 */
    .menu_bottom_overlay {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    /* 确保解锁卡片也居中 */
    .unlock_card {
        max-width: 800px;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 100% !important;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    /* 移动端触摸设备保持原有样式 */
    .btn:active {
        transform: scale(0.98);
    }
}

/* ============================================
   鼠标设备优化 - 悬停效果
   ============================================ */
@media (hover: hover) and (pointer: fine) {
    /* 书籍卡片悬停效果 */
    .book-item:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
        transition: all 0.3s ease;
    }
    
    .book-item:hover img {
        transform: scale(1.02);
        transition: transform 0.3s ease;
    }
    
    /* 首页横向滑动书籍悬停 */
    .list_item_box--shelf .book-item:hover {
        transform: translateY(-4px);
    }
    
    .list_item_box--shelf .book-item:hover > img {
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
    }
    
    /* 底部标签栏悬停 */
    .tabBar_item:hover {
        opacity: 0.85;
        transform: scale(1.05);
        transition: all 0.2s ease;
    }
    
    /* 按钮悬停效果 */
    .btn:hover,
    .book-read-btn:hover,
    .btn-add-library:hover {
        box-shadow: 0 6px 16px rgba(106, 13, 173, 0.3);
        transform: translateY(-2px);
        transition: all 0.2s ease;
    }
    
    /* 分类项悬停 */
    .category_item:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
        transform: translateY(-2px);
        transition: all 0.2s ease;
    }
    
    /* 章节项悬停 */
    .book-chapter-item--clickable:hover {
        background: #F5F0FA;
        transform: translateX(4px);
        transition: all 0.2s ease;
    }
    
    /* 搜索按钮悬停 */
    .icon-search:hover,
    .icon-category:hover {
        opacity: 0.7;
        transform: scale(1.1);
        transition: all 0.2s ease;
    }
    
    /* 返回按钮悬停 */
    .come-back:hover,
    .come-back-home:hover,
    .back-btn:hover {
        opacity: 0.7;
        transform: scale(1.1);
        transition: all 0.2s ease;
    }
    
    /* 标签chip悬停 */
    .book-chip--clickable:hover,
    .tag:hover {
        background: rgba(106, 13, 173, 0.15);
        transform: scale(1.05);
        transition: all 0.2s ease;
    }
    
    /* See all链接悬停 */
    .title-box .right:hover {
        opacity: 0.8;
        transform: translateX(3px);
        transition: all 0.2s ease;
    }
}

/* ============================================
   滚动条样式 - 桌面端优化
   ============================================ */
@media screen and (min-width: 768px) {
    /* 自定义滚动条 */
    ::-webkit-scrollbar {
        display: block;
        width: 10px;
        height: 10px;
    }
    
    ::-webkit-scrollbar-track {
        background: #F6F6F6;
        border-radius: 5px;
    }
    
    ::-webkit-scrollbar-thumb {
        background-color: rgba(106, 13, 173, 0.25);
        border-radius: 5px;
        border: 2px solid #F6F6F6;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background-color: rgba(106, 13, 173, 0.45);
    }
    
    ::-webkit-scrollbar-thumb:active {
        background-color: rgba(106, 13, 173, 0.6);
    }
    
    /* 阅读器滚动条 - 适配主题色 */
    .reader_container::-webkit-scrollbar-track {
        background: var(--bg-color, #F6F6F6);
    }
    
    .reader_container::-webkit-scrollbar-thumb {
        background-color: rgba(106, 13, 173, 0.2);
        border: 2px solid var(--bg-color, #F6F6F6);
    }
}

/* ============================================
   鼠标指针样式 - 桌面端优化
   ============================================ */
@media screen and (min-width: 768px) {
    /* 可点击元素添加指针样式 */
    .book-item,
    .category_item,
    .tabBar_item,
    .icon-search,
    .icon-category,
    .come-back,
    .come-back-home,
    .back-btn,
    .search-btn,
    .book-chip--clickable,
    .book-chapter-item--clickable,
    .title-box .right,
    .menu_content_item,
    .btn,
    .book-read-btn,
    .btn-add-library {
        cursor: pointer;
    }
    
    /* 禁用元素显示不可点击 */
    .book-read-btn:disabled,
    .btn:disabled {
        cursor: not-allowed;
    }
    
    /* 文本选择优化 */
    .reader_content .chapter .content {
        user-select: text;
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
    }
    
    /* 防止意外选择的元素 */
    .header-box,
    .tabBar_box,
    .book-item img,
    .category_item,
    .menu_content {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
}

/* ============================================
   性能优化 - 桌面端
   ============================================ */
@media screen and (min-width: 768px) {
    /* 启用硬件加速 */
    .book-item,
    .category_item,
    .tabBar_item,
    .btn,
    .book-read-btn {
        will-change: transform;
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    /* 平滑滚动 */
    html {
        scroll-behavior: smooth;
    }
    
    /* 图片懒加载优化 */
    img[loading="lazy"] {
        content-visibility: auto;
    }
}

