/* ===== 全局样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Comic Sans MS', 'Chalkboard SE', Roboto, sans-serif;
}

body {
    background-color: #d9c8a9;
    background-image: repeating-linear-gradient(45deg, #c4a48422 0px, #c4a48422 15px, #e3caa5 15px, #e3caa5 30px);
    min-height: 100vh;
    padding: clamp(1rem, 3vw, 2rem) clamp(0.8rem, 2.5vw, 1.5rem);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== 公用组件 ===== */
.not-found {
    font-size: clamp(1.5rem, 5vw, 2rem);
    text-align: center;
    color: #5f4a2e;
    padding: 50px;
}

.back-link {
    display: inline-block;
    background: #ad8b67;
    color: white;
    font-size: clamp(1.2rem, 4vw, 1.4rem);
    padding: clamp(6px, 2vw, 8px) clamp(20px, 5vw, 30px);
    border-radius: 60px;
    text-decoration: none;
    box-shadow: 0 5px 0 #5f4a2e;
    font-weight: bold;
    margin-bottom: 30px;
    transition: 0.1s linear;
    white-space: nowrap;
}

.back-link i {
    margin-right: 8px;
}

.back-link:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #5f4a2e;
}

@media (max-width: 480px) {
    .back-link {
        white-space: normal;
        text-align: center;
        width: 100%;
    }
}

/* ===== 书架样式 ===== */
.bookshelf {
    max-width: 1400px;
    margin: 0 auto;
    background: #b29262;
    padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1rem, 3vw, 2rem);
    border-radius: clamp(20px, 4vw, 30px) clamp(20px, 4vw, 30px) clamp(10px, 2vw, 15px) clamp(10px, 2vw, 15px);
    box-shadow: 0 20px 30px rgba(0,0,0,0.5), inset 0 2px 5px #efdbbe;
    border-bottom: 8px solid #7b5f40;
    position: relative;
}

.shelf-ledge {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20px;
    background: #7b5f40;
    border-radius: 0 0 15px 15px;
    box-shadow: inset 0 5px 8px #4f3e2b;
}

.shelf-section {
    margin-bottom: clamp(2rem, 5vw, 3.5rem);
}

.section-title {
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    font-weight: 600;
    color: #fff9e6;
    text-shadow: 3px 3px 0 #5f4a2e;
    padding-left: 15px;
    margin-bottom: 0.8rem;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.section-title i {
    margin-right: 15px;
    font-size: clamp(1.6rem, 4vw, 2rem);
    color: #ffe3a4;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: clamp(15px, 3vw, 28px) clamp(10px, 2vw, 18px);
    padding: 10px 5px;
}

@media (min-width: 768px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (min-width: 1024px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

.book-card {
    display: block;
    background: #fbf5e8;
    border-radius: 12px 12px 8px 8px;
    box-shadow: 0 10px 0 #7b5f40, 0 8px 15px rgba(0,0,0,0.5);
    transition: transform 0.2s ease, box-shadow 0.2s;
    overflow: hidden;
    border: 2px solid #f7e9cf;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 0 #7b5f40, 0 15px 25px rgba(0,0,0,0.6);
}

.book-cover {
    height: clamp(120px, 25vw, 160px);
    background-color: #d6c0a0;
    position: relative;
    border-bottom: 4px solid #af8f66;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2.5rem, 8vw, 3rem);
    color: #4f3e2b;
}

.book-category-tag {
    position: absolute;
    top: clamp(5px, 2vw, 10px);
    right: clamp(5px, 2vw, 10px);
    background: #ffb347;
    color: #2d2d2d;
    font-size: clamp(0.65rem, 2vw, 0.75rem);
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 30px;
    box-shadow: 0 3px 0 #b16300;
    text-transform: uppercase;
    white-space: nowrap;
}

.story-cover-overlay {
    background: rgba(80, 45, 20, 0.6);
    color: white;
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    width: 100%;
    text-align: center;
    padding: clamp(5px, 2vw, 10px) 0;
    font-weight: bold;
    backdrop-filter: blur(1px);
}

.book-info {
    padding: clamp(10px, 3vw, 15px) clamp(8px, 2.5vw, 12px) clamp(15px, 4vw, 20px);
    background: #fbf5e8;
    flex: 1;
}

.book-title {
    font-size: clamp(1.1rem, 3vw, 1.3rem);
    font-weight: 700;
    color: #3b2b1a;
    margin-bottom: 6px;
    word-break: break-word;
}

.book-desc {
    font-size: clamp(0.8rem, 2.5vw, 0.9rem);
    color: #5e4b33;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    word-break: break-word;
}

.credit-note {
    color: #eee6d2;
    text-align: right;
    margin-top: 10px;
    font-style: italic;
    font-size: clamp(0.8rem, 2vw, 1rem);
}

/* ===== 详情页样式 ===== */
.detail-container {
    max-width: 1200px;
    margin: 0 auto;
    background: #b29262;
    padding: clamp(1.5rem, 4vw, 2rem) clamp(1rem, 3vw, 2rem);
    border-radius: clamp(20px, 4vw, 30px) clamp(20px, 4vw, 30px) clamp(10px, 2vw, 15px) clamp(10px, 2vw, 15px);
    box-shadow: 0 20px 30px rgba(0,0,0,0.5), inset 0 2px 5px #efdbbe;
    border-bottom: 8px solid #7b5f40;
}

.detail-content {
    background: #fef7e9;
    border-radius: clamp(20px, 5vw, 40px);
    padding: clamp(15px, 4vw, 30px) clamp(15px, 4vw, 25px);
    box-shadow: inset 0 -5px 0 #baa077;
    border: 3px solid #ffe3b5;
}

.detail-title {
    font-size: clamp(2rem, 6vw, 2.8rem);
    text-align: center;
    margin-bottom: 20px;
    word-break: break-word;
    color: #3b2b1a;
}

.detail-description {
    text-align: center;
    font-size: clamp(1.1rem, 3.5vw, 1.4rem);
    color: #5f4a2e;
    margin-bottom: 30px;
}

/* ===== 图文分页样式 ===== */
.picture-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(15px, 4vw, 30px);
    margin: 30px 0 20px;
    flex-wrap: wrap;
}

/* 图文网格容器 */
.picture-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: clamp(15px, 3vw, 25px);
    margin-top: 30px;
    min-height: 400px;
    transition: opacity 0.3s ease;
}

.picture-items-grid.loading {
    opacity: 0.5;
}

@media (min-width: 768px) {
    .picture-items-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (min-width: 1024px) {
    .picture-items-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* 图文卡片样式 */
.picture-item-card {
    background: #f9e9cf;
    border-radius: clamp(15px, 4vw, 30px);
    padding: clamp(15px, 3vw, 20px) 10px;
    text-align: center;
    box-shadow: 0 8px 0 #bb9b74;
    border: 3px solid #fff1d6;
    transition: transform 0.2s, opacity 0.3s;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.picture-item-card:hover {
    transform: translateY(-5px);
}

/* 图片容器 - 等比例缩小 */
.item-image-container {
    width: 100%;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 15px;
    background-color: #fff;
    margin-bottom: 10px;
    padding: 5px;
}

.item-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

/* 中文行 */
.item-chinese-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
}

.item-chinese {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: bold;
    color: #2d5a27;
}

/* 英文行 */
.item-english-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-top: 1px dashed #bb9b74;
}

.item-english {
    font-size: clamp(1.3rem, 4.5vw, 1.8rem);
    font-style: italic;
    color: #a53f2b;
}

.sound-icon {
    font-size: clamp(1.3rem, 4vw, 1.8rem);
    color: #3c6e71;
    cursor: pointer;
    transition: color 0.2s;
    display: inline-block;
}

.sound-icon:hover {
    color: #284b4d;
}

/* 图片加载失败时的备用样式 */
.image-error {
    display: none;
    width: 100%;
    height: 100%;
    background-color: #f0f0f0;
    color: #999;
    font-size: 2rem;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

img.error {
    display: none;
}

img.error + .image-error {
    display: flex;
}

/* ===== 故事样式 ===== */
.story-detail-box {
    background: #fff3db;
    padding: clamp(15px, 4vw, 35px);
    border-radius: clamp(20px, 5vw, 40px);
}

.story-title {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
    border-bottom: 3px dotted #ad8b67;
    padding-bottom: 15px;
    margin-bottom: 20px;
    word-break: break-word;
    color: #3b2b1a;
}

.story-text {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    line-height: 1.6;
    margin: 30px 0;
    background: #ffeacb;
    padding: clamp(15px, 5vw, 30px);
    border-radius: clamp(20px, 5vw, 40px);
    min-height: clamp(150px, 40vh, 200px);
    word-break: break-word;
    transition: opacity 0.3s ease;
}

.story-text.loading {
    opacity: 0.5;
}

.story-read-buttons {
    display: flex;
    justify-content: center;
    gap: clamp(15px, 4vw, 30px);
    margin: 20px 0 10px;
    flex-wrap: wrap;
}

.read-btn {
    background: #ad8b67;
    border: none;
    padding: clamp(8px, 2.5vw, 12px) clamp(15px, 5vw, 30px);
    border-radius: 60px;
    font-size: clamp(1.1rem, 3.5vw, 1.4rem);
    color: white;
    box-shadow: 0 5px 0 #5f4a2e;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: 0.1s;
}

.read-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #5f4a2e;
}

.read-btn i {
    font-size: clamp(1.3rem, 4vw, 1.6rem);
}

/* ===== 翻页按钮通用样式 ===== */
.story-pagination,
.picture-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(15px, 4vw, 30px);
    margin: 30px 0 20px;
    flex-wrap: wrap;
}

.page-btn {
    background: #e3c184;
    border: none;
    padding: 12px 25px;
    border-radius: 50px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #2d2d2d;
    box-shadow: 0 4px 0 #997b4c;
    cursor: pointer;
    transition: all 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    justify-content: center;
}

.page-btn i {
    font-size: 1rem;
}

.page-btn:hover:not(:disabled) {
    background: #d4ac6e;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #997b4c;
}

.page-btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #997b4c;
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 0 #997b4c;
}

.current-page-indicator {
    font-size: 1.2rem;
    background: #f3d9aa;
    padding: 8px 20px;
    border-radius: 40px;
    font-weight: bold;
    color: #5f4a2e;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    min-width: 150px;
    text-align: center;
}

/* 小圆点导航 */
.page-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.page-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d9b382;
    cursor: pointer;
    transition: all 0.2s;
}

.page-dot.active {
    background: #7b5f40;
    transform: scale(1.3);
}

.page-dot:hover {
    background: #997b4c;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .story-pagination,
    .picture-pagination {
        gap: 10px;
    }
    
    .page-btn {
        padding: 10px 15px;
        font-size: 1rem;
        min-width: 90px;
    }
    
    .current-page-indicator {
        font-size: 1rem;
        padding: 6px 12px;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .story-pagination,
    .picture-pagination {
        flex-direction: column;
        gap: 12px;
    }
    
    .page-btn {
        width: 100%;
        max-width: 200px;
    }
    
    .current-page-indicator {
        order: -1;
        width: 100%;
    }
}

/* ===== 响应式调整 ===== */
@media (max-width: 896px) and (orientation: landscape) {
    body {
        padding: 1rem;
    }
    
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    
    .book-cover {
        height: 120px;
    }
    
    .picture-items-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
    
    .item-image-container {
        height: 110px;
    }
}

/* ===== 触摸设备优化 ===== */
@media (hover: none) {
    .book-card:hover,
    .picture-item-card:hover {
        transform: none;
    }
    
    .page-btn:hover:not(:disabled) {
        transform: none;
        box-shadow: 0 4px 0 #997b4c;
    }
    
    .page-btn:active:not(:disabled) {
        transform: translateY(4px);
    }
    
    .sound-icon, 
    .read-btn, 
    .page-btn, 
    .back-link {
        -webkit-tap-highlight-color: transparent;
    }
    
    .sound-icon:active, 
    .read-btn:active, 
    .page-btn:active {
        opacity: 0.7;
    }
}

/* ===== 打印样式 ===== */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .bookshelf, 
    .detail-container {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .sound-icon, 
    .read-btn, 
    .page-btn, 
    .back-link,
    .book-category-tag {
        display: none;
    }
}

/* ===== 图片和媒体 ===== */
img {
    max-width: 100%;
    height: auto;
    display: block;
}