/* 睡前故事网页 - 样式表 */
/* 版本: 4.0 - 代码质量优化 + 翻页动画 + 打印样式 */

/* ===== CSS 变量 ===== */
:root {
    /* 主题切换动画变量 */
    --transition-duration: 400ms;
    --transition-easing: ease-in-out;

    /* Eriko 设计规范 */
    --midnight-blue: #1A1F3C;
    --star-purple: #2D3561;
    --mint-dream: #7DD3C0;
    --warm-star: #FFD166;
    --lavender: #B8A9C9;
    --sakura: #FFB7C5;
    
    /* 主色调 */
    --bg-primary: #1A1F3C;
    --bg-secondary: #2D3561;
    --bg-card: rgba(45, 53, 97, 0.6);
    --text-primary: #F5F5F7;
    --text-secondary: #B8B8C8;
    
    /* 强调色 */
    --accent: #7DD3C0;
    --accent-hover: #5BC0A8;
    --accent-light: #9BE0D3;
    --star-color: #FFD166;
    --moon-glow: rgba(125, 211, 192, 0.3);
    
    /* 其他 */
    --shadow: rgba(0, 0, 0, 0.4);
    --glow: rgba(125, 211, 192, 0.15);
    --border-radius: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 日间模式 - Eriko 设计 */
[data-theme="light"] {
    --bg-primary: #FFF8DC;
    --bg-secondary: #FFE4B5;
    --bg-card: rgba(255, 255, 255, 0.85);
    --text-primary: #4A4035;
    --text-secondary: #8A7B6A;
    --accent: #228B22;
    --accent-hover: #1B6B1B;
    --accent-light: #3CB371;
    --shadow: rgba(0, 0, 0, 0.08);
    --glow: rgba(34, 139, 34, 0.1);
}

/* ===== 基础重置 ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    /* 主题切换平滑过渡 */
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing, ease-in-out),
        color var(--transition-duration, 400ms) var(--transition-easing, ease-in-out);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-primary) 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        color var(--transition-duration, 400ms) var(--transition-easing);
}

/* ===== 粒子背景 ===== */
.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    transition: opacity var(--transition-duration, 400ms) var(--transition-easing);
}

.particle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.6;
    animation: float-particle linear infinite;
}

.particle.star {
    background: var(--star-color);
    box-shadow: 0 0 10px var(--star-color);
}

.particle.firefly {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

@keyframes float-particle {
    0% { transform: translateY(100vh) scale(0); opacity: 0; }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { transform: translateY(-100px) scale(1); opacity: 0; }
}

/* ===== 月亮 ===== */
.moon {
    position: fixed;
    top: 40px;
    right: 50px;
    font-size: 3.5rem;
    z-index: 1;
    /* animation: float-moon 8s ease-in-out infinite; */
    filter: drop-shadow(0 0 30px var(--moon-glow));
    cursor: pointer;
    transition:
        filter var(--transition-duration, 400ms) var(--transition-easing),
        transform 200ms ease,
        opacity 400ms ease-in-out;
}

@keyframes float-moon {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

/* ===== 头部 ===== */
.header {
    text-align: center;
    padding: 60px 20px 30px;
    position: relative;
    z-index: 10;
}

.header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--warm-star) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#greeting {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

#greeting .highlight-name {
    color: var(--accent);
    font-weight: 600;
}

.toolbar {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.theme-toggle {
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    cursor: pointer;
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        border-color var(--transition-duration, 400ms) var(--transition-easing),
        box-shadow var(--transition-duration, 400ms) var(--transition-easing),
        transform 200ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(20deg);
    box-shadow: 0 0 30px var(--moon-glow);
}

/* ===== 欢迎横幅 ===== */
.welcome-banner {
    max-width: 700px;
    margin: 0 auto 30px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.welcome-text {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    padding: 20px 30px;
    border-radius: var(--border-radius);
    font-size: 1.2rem;
    text-align: center;
    box-shadow: 0 10px 30px var(--glow);
}

.welcome-text .highlight-name {
    color: var(--warm-star);
    font-weight: 700;
}

/* ===== 统计区域 ===== */
.stats-section {
    max-width: 700px;
    margin: 0 auto 30px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

/* ===== 统计页面标签栏 ===== */
.stats-tabs {
    display: flex;
    gap: 8px;
    padding: 15px 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.stats-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 1;
    min-width: 70px;
    padding: 8px 6px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.tab-btn:not(.active):hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ===== 统计概览 ===== */
.stats-overview {
    max-width: 700px;
    margin: 0 auto 20px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(125, 211, 192, 0.2);
    backdrop-filter: blur(10px);
}

.stat-item {
    text-align: center;
}

.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

/* ===== 继续阅读卡片 ===== */
.continue-section {
    max-width: 700px;
    margin: 0 auto 30px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.section-title {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    padding-left: 10px;
}

.continue-card {
    background: var(--bg-card);
    border: 1px solid rgba(125, 211, 192, 0.3);
    border-radius: var(--border-radius);
    padding: 20px 25px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        border-color var(--transition-duration, 400ms) var(--transition-easing),
        box-shadow var(--transition-duration, 400ms) var(--transition-easing),
        transform 300ms ease;
    backdrop-filter: blur(10px);
}

.continue-card:hover {
    transform: translateX(10px);
    border-color: var(--accent);
    box-shadow: 0 10px 30px var(--glow);
}

.continue-icon {
    font-size: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.continue-icon img {
    width: 2.5rem;
    height: 2.5rem;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 4px;
}

.continue-info {
    flex: 1;
}

.continue-info h3 {
    font-size: 1.1rem;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.continue-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.continue-progress {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.continue-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--warm-star));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.continue-arrow {
    font-size: 1.5rem;
    color: var(--accent);
}

/* ===== 每日推荐 ===== */
.recommend-section {
    max-width: 700px;
    margin: 0 auto 30px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.recommend-card {
    background: linear-gradient(135deg, rgba(125, 211, 192, 0.2) 0%, rgba(255, 209, 102, 0.2) 100%);
    border: 2px solid var(--accent);
    border-radius: var(--border-radius);
    padding: 25px;
    cursor: pointer;
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        border-color var(--transition-duration, 400ms) var(--transition-easing),
        box-shadow var(--transition-duration, 400ms) var(--transition-easing),
        transform 300ms ease,
        opacity 300ms ease;
    position: relative;
    overflow: hidden;
}

.recommend-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px var(--glow);
}

.recommend-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--warm-star);
    color: var(--bg-primary);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.recommend-content {
    display: flex;
    gap: 20px;
    align-items: center;
}

.recommend-icon {
    font-size: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.recommend-icon img {
    width: 4rem;
    height: 4rem;
    object-fit: cover;
    border-radius: 12px;
}

.recommend-info h3 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.recommend-info p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
}

.recommend-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.recommend-tags span {
    background: var(--bg-card);
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    color: var(--accent);
}

/* ===== 分类筛选 ===== */
.category-section {
    max-width: 700px;
    margin: 0 auto 20px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.category-filter {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.category-tag {
    background: var(--bg-card);
    border: 1px solid rgba(125, 211, 192, 0.2);
    color: var(--text-secondary);
    padding: 8px 20px;
    border-radius: 25px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.category-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.category-tag.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ===== 搜索栏 ===== */
.search-section {
    max-width: 700px;
    margin: 0 auto 20px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid rgba(125, 211, 192, 0.2);
    border-radius: 30px;
    padding: 5px 5px 5px 15px;
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--glow);
}

.search-icon {
    font-size: 1.2rem;
    margin-right: 10px;
    opacity: 0.6;
}

#searchInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 10px 0;
    outline: none;
}

#searchInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.search-clear {
    background: rgba(125, 211, 192, 0.2);
    border: none;
    color: var(--accent);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.search-clear:hover {
    background: var(--accent);
    color: white;
}

.search-result-count {
    text-align: center;
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--accent);
}

/* ===== 时间筛选 ===== */
.time-section {
    max-width: 700px;
    margin: 0 auto 20px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.time-filter {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.time-tag {
    background: var(--bg-card);
    border: 1px solid rgba(255, 209, 102, 0.2);
    color: var(--text-secondary);
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.time-tag:hover {
    border-color: var(--warm-star);
    color: var(--warm-star);
}

.time-tag.active {
    background: var(--warm-star);
    border-color: var(--warm-star);
    color: var(--bg-primary);
}

/* ===== 分页 ===== */
.pagination-container {
    max-width: 700px;
    margin: 30px auto;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.page-btn {
    background: var(--bg-card);
    border: 1px solid rgba(125, 211, 192, 0.2);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    min-width: 36px;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.page-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-ellipsis {
    color: var(--text-secondary);
    padding: 0 5px;
}

.page-info {
    text-align: center;
    margin-top: 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== 主内容区 ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 10;
}

/* ===== 故事卡片网格 ===== */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

/* ===== 故事卡片（默认网格） ===== */
.story-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 8px 32px var(--shadow);
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        border-color var(--transition-duration, 400ms) var(--transition-easing),
        box-shadow var(--transition-duration, 400ms) var(--transition-easing),
        transform 300ms ease,
        opacity 300ms ease;
    border: 1px solid rgba(125, 211, 192, 0.1);
    backdrop-filter: blur(10px);
    animation: fadeInUp 0.5s ease backwards;
}

/* ===== 瀑布流卡片（stats.html 使用） ===== */
.story-card-masonry {
    break-inside: avoid;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 8px 32px var(--shadow);
    transition:
        background-color var(--transition-duration, 400ms) var(--transition-easing),
        border-color var(--transition-duration, 400ms) var(--transition-easing),
        box-shadow var(--transition-duration, 400ms) var(--transition-easing),
        transform 300ms ease;
    border: 1px solid rgba(125, 211, 192, 0.1);
    backdrop-filter: blur(10px);
    animation: fadeInUp 0.5s ease backwards;
    cursor: pointer;
}

.story-card-masonry:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px var(--shadow), 0 0 20px var(--glow);
    border-color: rgba(125, 211, 192, 0.3);
}

.story-card-masonry .story-card-image {
    height: 180px;
}

.story-card-masonry .story-card-content {
    padding: 14px 16px;
}

.masonry-title {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
    cursor: pointer;
}

.masonry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.masonry-tag {
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(125, 211, 192, 0.1);
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.masonry-date {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===== 故事列表容器（index.html 用 grid，stats.html 用 masonry 覆盖） ===== */
#storyList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

/* stats.html 使用的瀑布流样式由 .story-card-masonry 继承的全局 .story-grid 样式提供 */

.story-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 50px var(--shadow), 0 0 30px var(--glow);
    border-color: rgba(125, 211, 192, 0.3);
}

.story-card-image {
    width: 100%;
    height: 160px;
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.story-card-image::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.1) 50%, transparent 60%);
    animation: shimmer 3s infinite;
}

.story-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-icon-fallback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes shimmer {
    0% { transform: translateX(-100%) translateY(-100%); }
    100% { transform: translateX(100%) translateY(100%); }
}

.story-card-content {
    padding: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.card-header h3 {
    font-size: 1.15rem;
    color: var(--text-primary);
    cursor: pointer;
    flex: 1;
}

.fav-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    transition: var(--transition);
    padding: 5px;
    opacity: 0.6;
}

.fav-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}

.fav-btn.active {
    opacity: 1;
}

.story-card-content > p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 15px;
    cursor: pointer;
}

.story-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.highlight-name {
    color: var(--accent);
    font-weight: 600;
    text-shadow: 0 0 10px var(--glow);
}

/* ===== 阅读页布局 ===== */
.reader-container {
    max-width: 850px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 阅读页导航 */
.reader-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 10px 0;
    flex-wrap: wrap;
    gap: 10px;
}

.reader-nav-title {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
    text-align: center;
    flex: 1;
    padding: 0 20px;
    order: 2;
}

.back-btn {
    background: var(--bg-card);
    border: 2px solid var(--accent);
    color: var(--accent);
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
    order: 1;
}

.back-btn:hover {
    background: var(--accent);
    color: white;
}

/* 分享按钮 */
.share-btn {
    background: var(--bg-card);
    border: 2px solid var(--accent);
    color: var(--accent);
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    order: 3;
}

.share-btn:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.1);
}

/* 音频播放器 */
.audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 30px;
    border: 1px solid rgba(125, 211, 192, 0.2);
    backdrop-filter: blur(10px);
    order: 4;
}

.audio-btn {
    background: var(--accent);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px var(--glow);
}

.audio-progress {
    width: 100px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
}

.audio-progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

.audio-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 40px;
}

/* 阅读进度条 */
.reading-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-bottom: 30px;
    overflow: hidden;
}

.reading-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--warm-star));
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--glow);
}

/* ===== 书本区域 - 3D翻页动画 ===== */
.book-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    margin-bottom: 30px;
    perspective: 1500px;
    perspective-origin: center center;
    z-index: 1;
    position: relative;
    min-height: 0;
}

.book {
    width: 100%;
    max-width: 600px;
    height: auto;
    min-height: 800px;
    max-height: 85vh;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: 0 20px 60px var(--shadow);
    border: none;
    backdrop-filter: blur(20px);
    position: relative;
    overflow-y: auto;
    transform-style: preserve-3d;
    z-index: 1;
    display: flex;
    flex-direction: column;
    scrollbar-width: none; /* Firefox */
}
.book::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Edge */
}

.book::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--warm-star), var(--accent));
    opacity: 0.5;
}

/* 书脊效果 */
.book::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.1), transparent);
    transform: translateX(-50%);
    pointer-events: none;
    opacity: 0;
}

/* 3D翻页 - 页面容器 */
.book-pages {
    position: relative;
    width: 100%;
    min-height: 800px;
    padding-bottom: 60px;
    transform-style: preserve-3d;
    z-index: 2;
    flex: 1 1 auto;
}

/* 单个书页 */
.book-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 0.7s cubic-bezier(0.4, 0.2, 0.2, 1);
    backface-visibility: hidden;
    cursor: pointer;
    /* GPU 加速优化 */
    will-change: transform;
    transform: translateZ(0);
    z-index: 2; /* 确保书页在 book 内部，不影响 controls */
    overflow: hidden;
}

/* 书页正面 */
.book-page-front {
    position: relative;
    width: 100%;
    height: 100%;
    background: transparent;
    border-radius: 8px;
    padding: 20px 30px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 书页背面 */
.book-page-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-card);
    border-radius: 8px;
    padding: 30px;
    transform: rotateY(180deg);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.1);
}

/* 翻页动画进行中 */
.book-page.flipped {
    transform: rotateY(-180deg);
}

/* 翻页动画反向（往回翻） */
.book-page.flipping-back {
    transform: rotateY(180deg);
}

/* 书页堆叠效果 - 后渲染的页面（当前页）在上层 */
.book-page:nth-child(1) { z-index: 1; }
.book-page:nth-child(2) { z-index: 2; }
.book-page:nth-child(3) { z-index: 3; }

/* 页面内容样式 */
.page {
    background: transparent;
    transition: opacity 0.3s ease, transform 0.3s ease;
    min-height: 0;
}

.page-header {
    text-align: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.chapter-tag {
    background: rgba(125, 211, 192, 0.15);
    color: var(--accent);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 1px solid rgba(125, 211, 192, 0.3);
    display: inline-block;
}

.page-content {
    font-size: 1.1rem;
    line-height: 1.9;
    color: var(--text-primary);
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    max-height: 100%;
}

.page-content p {
    margin-bottom: 1.2em;
    text-indent: 2em;
}

.page-content .highlight-name {
    color: var(--accent);
    font-weight: 600;
}

.ending {
    text-align: center;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px dashed rgba(125, 211, 192, 0.3);
}

.ending-text {
    font-size: 1.2rem;
    color: var(--accent);
    font-weight: 500;
}

.ending-icon {
    font-size: 2rem;
    margin-top: 10px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* 翻页提示 - 底部翻页指引 */
.flip-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 0 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    opacity: 0.7;
    flex-shrink: 0;
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
}

.flip-hint-icon {
    animation: swipe-hint 1.5s ease-in-out infinite;
}

@keyframes swipe-hint {
    0%, 100% { transform: translateX(-5px); opacity: 0.5; }
    50% { transform: translateX(5px); opacity: 1; }
}

/* 触摸反馈 */
.book-page:active .book-page-front {
    box-shadow: inset 0 0 20px rgba(125, 211, 192, 0.1);
}

/* 日间模式适配 */
[data-theme="light"] .book-page-back {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.05);
}

/* 响应式 */
@media (max-width: 768px) {
    .book {
        height: auto;
        min-height: 900px;
        max-height: 85vh;
        border-radius: 16px;
        overflow-y: auto;
    }
    
    .book-pages {
        min-height: 800px;
    }
    
    .book-page {
        height: 100%;
    }
    
    .book-page-front,
    .book-page-back {
        height: 100%;
        padding: 15px 20px;
        flex-shrink: 0;
        overflow: hidden;
    }
    
    .book-page-front {
        display: flex;
        flex-direction: column;
    }
    
    .page-header {
        margin-bottom: 10px;
        flex-shrink: 0;
    }
    
    .page-illustration {
        height: auto;
        aspect-ratio: 16 / 9;
        margin-bottom: 10px;
        flex-shrink: 0;
    }
    
    .page-content {
        font-size: 0.95rem;
        line-height: 1.7;
        flex: 1 1 auto;
        min-height: 300px;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ===== 翻页控制 ===== */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    padding: 20px 0;
    position: static;
    pointer-events: auto;
}

.nav-btn {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    border: none;
    color: white;
    padding: 14px 28px;
    border-radius: 30px;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    box-shadow: 0 8px 25px var(--glow);
}

.nav-btn:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 35px var(--glow);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.nav-btn svg {
    width: 20px;
    height: 20px;
}

.page-dots {
    display: flex;
    gap: 8px;
    align-items: center;
}

.page-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(125, 211, 192, 0.3);
    cursor: pointer;
    transition: var(--transition);
}

.page-dot:hover {
    background: rgba(125, 211, 192, 0.6);
}

.page-dot.active {
    background: var(--accent);
    box-shadow: 0 0 10px var(--glow);
    transform: scale(1.3);
}

/* ===== 页码指示器 ===== */
.page-indicator {
    text-align: center;
    padding: 8px 0;
    font-size: 1rem;
    color: var(--text);
    opacity: 0.7;
    letter-spacing: 0.5px;
}

.page-indicator span {
    font-weight: 600;
    color: var(--accent);
}

/* ===== 个性化设置区域 ===== */
.personalization {
    max-width: 600px;
    margin: 0 auto 40px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.name-input-group {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 25px;
    border: 1px solid rgba(125, 211, 192, 0.2);
    backdrop-filter: blur(10px);
}

.name-input-group label {
    display: block;
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 12px;
    font-weight: 500;
}

.input-wrapper {
    display: flex;
    gap: 10px;
}

#childName {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(125, 211, 192, 0.3);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 1rem;
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
}

#childName::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

#childName:focus {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--glow);
}

.save-btn {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    border: none;
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--glow);
}

.hint {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== 页脚 ===== */
.footer {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 1rem;
    position: relative;
    z-index: 10;
}

/* ===== 动画 ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .header {
        padding: 50px 15px 20px;
    }
    
    .header h1 {
        font-size: 1.7rem;
    }
    
    .moon {
        font-size: 2.5rem;
        top: 20px;
        right: 20px;
    }
    
    .welcome-text {
        font-size: 1rem;
        padding: 15px 20px;
    }
    
    .stats-grid {
        gap: 15px;
        padding: 15px;
    }
    
    .stat-number {
        font-size: 1.4rem;
    }
    
    .recommend-content {
        flex-direction: column;
        text-align: center;
    }
    
    .recommend-icon {
        font-size: 3rem;
    }
    
    .story-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .reader-nav {
        flex-wrap: wrap;
    }
    
    .reader-nav-title {
        order: 0;
        width: 100%;
        padding: 10px 0;
    }
    
    .back-btn, .share-btn {
        order: 1;
    }
    
    .audio-player {
        order: 2;
        width: 100%;
        justify-content: center;
    }
    
    .book {
        padding: 25px;
        min-height: 350px;
        height: auto;
    }

    .book-pages {
        min-height: 300px;
    }
    
    .page-content {
        font-size: 0.95rem;
        line-height: 1.7;
        flex: 1;
        overflow-y: auto;
    }
    
    .controls {
        gap: 20px;
    }
    
    .nav-btn {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
    
    .nav-btn span {
        display: none;
    }
}

/* 故事页手机端适配 */
@media (max-width: 480px) {
    .book {
        width: 360px !important;
        max-width: 360px !important;
        min-height: 700px !important;
        max-height: 85vh !important;
        padding: 15px !important;
        border-radius: 16px !important;
    }
    
    .book-pages {
        min-height: 650px !important;
    }
    
    .page-illustration {
        aspect-ratio: 4 / 3 !important;
        margin-bottom: 10px !important;
    }
    
    .page-content {
        font-size: 0.9rem !important;
        line-height: 1.65 !important;
        min-height: 250px !important;
    }
    
    .controls {
        gap: 15px !important;
        padding: 15px 0 !important;
    }
    
    .nav-btn {
        padding: 10px 18px !important;
        font-size: 0.85rem !important;
    }
}

/* 360px / 375px / 414px / 480px 宽度适配 */
@media (max-width: 420px) {
    .book {
        width: calc(100vw - 30px) !important;
        max-width: 360px !important;
        min-height: 650px !important;
    }
    
    .page-content {
        font-size: 0.85rem !important;
        line-height: 1.6 !important;
    }
}

@media (max-width: 480px) {
    .reader-container {
        padding: 10px;
    }
    
    .book {
        width: 360px !important;
        min-height: 700px !important;
    }
    
    .book-page-front,
    .book-page-back {
        padding: 12px 15px !important;
    }
}

@media (max-width: 480px) {
    .input-wrapper {
        flex-direction: column;
    }
    
    .save-btn {
        width: 100%;
    }
    
    .continue-card {
        flex-wrap: wrap;
    }
    
    .page-dots {
        gap: 6px;
    }
    
    .page-dot {
        width: 8px;
        height: 8px;
    }
}

/* ===== 无障碍 ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* ===== 打印样式 ===== */
@media print {
    /* 隐藏不必要的元素 */
    .particles,
    .moon,
    .reader-nav,
    .controls,
    .reading-progress,
    .page-dots,
    .audio-player,
    .toolbar,
    .fav-btn,
    .category-section,
    .personalization,
    .stats-section,
    .continue-section,
    .recommend-section,
    .welcome-banner,
    .footer {
        display: none !important;
    }
    
    /* 重置背景和文字颜色 */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
    }
    
    /* 书本样式 */
    .book {
        background: white !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        padding: 20pt !important;
        max-width: 100% !important;
    }
    
    /* 页面内容 */
    .page-content {
        color: black !important;
        font-size: 11pt !important;
        line-height: 1.6 !important;
    }
    
    .page-content .highlight-name {
        color: #0066cc !important;
        font-weight: bold !important;
    }
    
    /* 章节标题 */
    .chapter-tag {
        background: #f0f0f0 !important;
        color: black !important;
        border: 1px solid #ccc !important;
    }
    
    /* 结尾部分 */
    .ending {
        border-top: 1px solid #ccc !important;
        margin-top: 20pt !important;
    }
    
    .ending-text {
        color: #0066cc !important;
    }
    
    /* 故事标题 */
    .reader-nav-title {
        color: black !important;
        font-size: 16pt !important;
        text-align: center !important;
        display: block !important;
        margin-bottom: 20pt !important;
    }
    
    /* 确保链接打印为黑色 */
    a {
        color: black !important;
        text-decoration: none !important;
    }
    
    /* 分页控制 */
    .page {
        page-break-inside: avoid;
    }
    
    /* 故事卡片打印友好 */
    .story-card {
        break-inside: avoid;
        border: 1px solid #ccc !important;
        background: white !important;
    }
}

/* ===== 离线提示横幅 ===== */
#offline-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: linear-gradient(135deg, #191970 0%, #2D3561 100%);
    color: #F8F9FA;
    padding: 16px 20px;
    box-shadow: 0 4px 20px rgba(25, 25, 112, 0.4);
    font-family: inherit;
    animation: slideDown 0.4s ease-out;
}

#offline-banner.show {
    display: block;
}

.offline-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    max-width: 600px;
    margin: 0 auto;
}

.offline-icon {
    font-size: 28px;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 8px rgba(255, 209, 102, 0.4));
}

.offline-text {
    text-align: left;
}

.offline-text strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.offline-text p {
    margin: 0;
    font-size: 13px;
    color: rgba(248, 249, 250, 0.8);
    line-height: 1.4;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 离线时顶部留白，避免内容被横幅遮挡 */
body.offline-active {
    padding-top: 60px;
}

body.offline-active .header {
    margin-top: 0;
}

/* ===== PWA 安装提示 ===== */
#install-banner {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: linear-gradient(135deg, var(--midnight-blue) 0%, var(--star-purple) 100%);
    border-top: 1px solid rgba(125, 211, 192, 0.3);
    padding: 14px 20px;
    justify-content: center;
    align-items: center;
    gap: 16px;
    font-family: inherit;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.4);
    animation: slideUpInstall 0.4s ease-out;
}

#install-banner span {
    color: var(--text-primary);
    font-size: 0.95rem;
    flex: 1;
}

#btn-install {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    border: none;
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

#btn-install:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--glow);
}

#btn-dismiss {
    background: transparent;
    border: 1px solid rgba(184, 184, 200, 0.4);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

#btn-dismiss:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

@keyframes slideUpInstall {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}


/* 页面插画 */
.page-illustration {
    width: 100%;
    aspect-ratio: 16 / 9;
    margin-bottom: 15px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
}

.page-illustration img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== 横向故事卡片（stats.html 左图右文） ===== */
.story-card-masonry-horizontal {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    padding: 6px 10px !important;
}

.story-card-masonry-horizontal .story-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 6px 10px;
    gap: 3px;
}

.story-card-masonry-horizontal .story-card-image {
    flex: 0 0 50px;
    width: 50px !important;
    height: 50px !important;
}

.story-card-masonry-horizontal .story-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-card-masonry-horizontal .story-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 12px 14px;
}

.story-card-masonry-horizontal .masonry-title {
    font-size: 0.85rem;
    line-height: 1.3;
    /* 限制1行，超出省略 */
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-card-masonry-horizontal .masonry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.story-card-masonry-horizontal .masonry-tag {
    max-width: 55%;
    font-size: 0.7rem;
}

.story-card-masonry-horizontal .masonry-date {
    font-size: 0.68rem;
}
