/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Serif SC', '霞鹜文楷', '方正清刻本悦宋', serif;
    background-color: #F5F2EB; /* 宣纸白 */
    color: #2D2D2D; /* 墨黑 */
    line-height: 1.8;
    overflow-x: hidden;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="%23F5F2EB"/><path d="M20,20 Q40,5 60,20 T100,20 M20,40 Q40,25 60,40 T100,40 M20,60 Q40,45 60,60 T100,60 M20,80 Q40,65 60,80 T100,80" stroke="%23F0EDE5" stroke-width="0.5" fill="none"/></svg>');
    background-size: 300px;
    /* 优化渲染性能 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Screen reader only class for accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 优化动画性能 */
.letter-page,
.snowflake,
.leaf,
.ripple {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 首屏雪落效果 */
#snowfall-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: #F5F2EB;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    overflow: hidden;
}

.snowflake {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    pointer-events: none;
}

#snowfall-screen h1 {
    font-size: 24px;
    text-align: center;
    margin-bottom: 30px;
    letter-spacing: 0.05em;
    color: #2D2D2D;
    font-weight: 500;
    max-width: 80%;
    line-height: 1.3;
}

#snowfall-screen p {
    font-size: 14px;
    opacity: 0.7;
    text-decoration: underline;
    cursor: pointer;
    color: #2D2D2D;
    transition: opacity 0.3s ease;
}

#snowfall-screen p:hover {
    opacity: 1;
}

/* 主信展示区 */
#main-letter {
    display: none;
    padding: 80px 20px;
    max-width: 800px;
    margin: 0 auto;
    background-color: #F8F6F0; /* 玉兰白 */
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
    position: relative;
    min-height: 100vh;
}

.letter-page {
    display: none;
    padding: 40px;
    background-color: #F5F2EB;
    min-height: 60vh;
    position: relative;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    border-radius: 4px;
}

.letter-page.active {
    display: block;
    animation: fadeIn 0.8s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.letter-page h2 {
    font-size: 24px;
    margin-bottom: 30px;
}

/* 音乐播放器样式 */
.music-player {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background-color: #F8F6F0;
    border-radius: 30px;
    padding: 15px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    border: 1px solid #e8e4d9;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.play-pause-btn {
    background-color: #D4B16A;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.play-pause-btn:hover {
    background-color: #c09d53;
}

.progress-container {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 200px;
}

.time-display {
    font-size: 12px;
    color: #666;
    min-width: 40px;
}

.progress-bar {
    flex: 1;
    margin: 0 10px;
    height: 5px;
    border-radius: 5px;
    background-color: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
}

.progress-bar::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-slider {
    width: 80px;
    height: 5px;
    border-radius: 5px;
    background-color: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
}

.player-status {
    font-size: 12px;
    color: #777;
    margin-left: 10px;
    min-width: 100px;
}
.letter-page h2 {
    color: #2D2D2D;
    text-align: center;
    font-weight: 500;
}

.letter-page p {
    font-size: 16px;
    margin-bottom: 20px;
    color: #2D2D2D;
    text-align: justify;
    text-indent: 2em;
    hyphens: auto; /* 优化文字换行 */
    word-wrap: break-word; /* 防止长单词溢出 */
}

.keyword {
    position: relative;
    cursor: pointer;
    color: #D4B16A; /* 银杏黄 */
    transition: color 0.3s ease;
    border-bottom: 1px dotted currentColor; /* 为关键词添加下划线以增强可访问性 */
}

.keyword:hover, .keyword:focus {
    color: #8B7355; /* 茶色 */
    outline: none; /* 为键盘导航提供视觉反馈 */
}

.page-indicator {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: #8B7355; /* 茶色 */
}

/* 藏信按钮 */
#save-letter {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: none;
    border: none;
    font-size: 14px;
    color: #8B7355;
    cursor: pointer;
    text-decoration: underline;
    transition: text-decoration 0.3s ease;
    z-index: 10;
}

#save-letter:hover {
    text-decoration: none;
}

/* 音量控制 */
#volume-control {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.8);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
}

#volume-control:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.9);
}

/* 结尾区域 */
#end-screen {
    display: none;
    padding: 80px 20px;
    text-align: center;
    background-color: #F5F2EB;
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#end-screen h3 {
    font-size: 18px;
    margin-bottom: 20px;
    color: #2D2D2D;
}

#end-screen p {
    font-size: 16px;
    line-height: 2.0;
    letter-spacing: 1px;
    color: #2D2D2D;
    max-width: 600px;
}

/* 微交互效果 */
.falling-leaves {
    position: absolute;
    pointer-events: none;
}

.leaf {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: #D4B16A; /* 银杏黄 */
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.ripple {
    position: absolute;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* 回声墙 */
#echo-wall {
    margin-top: 40px;
    font-size: 12px;
    color: #A3B1A3; /* 微青 */
    cursor: pointer;
    text-align: center;
    transition: color 0.3s ease;
}

#echo-wall:hover {
    color: #8B7355; /* 茶色 */
}

#echo-input {
    display: none;
    width: 200px;
    height: 40px;
    margin: 10px auto 0;
    padding: 10px;
    border: 1px solid #A3B1A3;
    border-radius: 4px;
    font-family: inherit;
    background-color: #F8F6F0;
    color: #2D2D2D;
    text-align: center;
}

#echo-container {
    margin-top: 20px;
    padding: 15px;
    background-color: #F0EDE5; /* 微黄 */
    border-radius: 8px;
    text-align: center;
    min-height: 50px;
}

/* 音乐播放器样式 */
#music-player {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(212, 177, 106, 0.3);
    max-width: calc(100% - 40px);
    margin: 0 auto;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.play-pause-btn {
    background: #D4B16A;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.play-pause-btn:hover {
    background: #8B7355;
    transform: scale(1.05);
}

.progress-container {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 8px;
}

.time {
    font-size: 12px;
    color: #8B7355;
    min-width: 40px;
    text-align: center;
}

.progress-bar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #F0EDE5;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
}

.progress-bar::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #D4B16A;
    cursor: pointer;
    border: none;
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-slider {
    width: 80px;
    height: 6px;
    border-radius: 3px;
    background: #F0EDE5;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #A3B1A3;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #A3B1A3;
    cursor: pointer;
    border: none;
}

.player-status {
    text-align: center;
    font-size: 12px;
    color: #8B7355;
    height: 18px;
}



/* 响应式设计 */
/* 超小屏幕 (手机, 小于576px) */
@media (max-width: 575.98px) {
    #snowfall-screen h1 {
        font-size: 18px;
        padding: 0 15px;
        line-height: 1.4;
    }
    
    #snowfall-screen p {
        font-size: 13px;
    }
    
    #main-letter {
        padding: 50px 10px;
        min-height: 100vh;
    }
    
    .letter-page {
        padding: 25px 15px;
        min-height: auto;
    }
    
    .letter-page h2 {
        font-size: 20px;
        margin-bottom: 20px;
    }
    
    .letter-page p {
        font-size: 14px;
        margin-bottom: 15px;
        line-height: 1.7;
    }
    
    .page-indicator {
        font-size: 13px;
    }
    
    #end-screen {
        padding: 50px 10px;
    }
    
    #end-screen p {
        font-size: 14px;
        line-height: 1.7;
        letter-spacing: 0.5px;
    }
    
    #save-letter {
        bottom: 20px;
        right: 20px;
        font-size: 13px;
    }
    
    #volume-control {
        top: 15px;
        right: 15px;
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    /* 音乐播放器响应式调整 */
    .music-player {
        padding: 12px 15px;
        border-radius: 25px;
    }
    
    .player-controls {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }
    
    .progress-container {
        width: 100%;
        justify-content: center;
    }
    
    .time-display {
        font-size: 11px;
    }
    
    .progress-bar {
        flex: 1;
        min-width: 150px;
    }
    
    .volume-container {
        width: 100%;
        justify-content: center;
    }
}

/* 小屏幕 (手机, 576px及以上) */
@media (min-width: 576px) and (max-width: 767.98px) {
    #snowfall-screen h1 {
        font-size: 20px;
        padding: 0 20px;
    }
    
    #main-letter {
        padding: 60px 15px;
    }
    
    .letter-page {
        padding: 30px 20px;
    }
    
    .letter-page h2 {
        font-size: 21px;
    }
    
    .letter-page p {
        font-size: 15px;
    }
    
    #end-screen {
        padding: 60px 15px;
    }
    
    #end-screen p {
        font-size: 15px;
        line-height: 1.75;
    }
}

/* 中等屏幕 (平板, 768px及以上) */
@media (min-width: 768px) and (max-width: 991.98px) {
    #main-letter {
        padding: 70px 20px;
        max-width: 700px;
    }
    
    .letter-page {
        padding: 35px 25px;
    }
    
    .letter-page h2 {
        font-size: 22px;
    }
    
    .letter-page p {
        font-size: 15px;
    }
    
    #end-screen {
        padding: 70px 20px;
    }
    
    .page-indicator {
        font-size: 14px;
    }
}

/* 大屏幕 (桌面, 992px及以上) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    #main-letter {
        padding: 80px 25px;
        max-width: 750px;
    }
    
    .letter-page {
        padding: 40px 30px;
    }
    
    .letter-page h2 {
        font-size: 23px;
    }
    
    .letter-page p {
        font-size: 16px;
    }
    
    #end-screen {
        padding: 80px 25px;
    }
}

/* 超大屏幕 (大桌面, 1200px及以上) */
@media (min-width: 1200px) {
    #main-letter {
        padding: 80px 30px;
        max-width: 800px;
    }
    
    .letter-page {
        padding: 45px 35px;
    }
    
    .letter-page h2 {
        font-size: 24px;
    }
    
    .letter-page p {
        font-size: 16px;
    }
    
    #end-screen {
        padding: 80px 30px;
    }
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* 横屏设备优化 */
@media (orientation: landscape) and (max-height: 500px) {
    #snowfall-screen h1 {
        font-size: 18px;
        margin-bottom: 20px;
    }
    
    .letter-page {
        padding: 20px 15px;
    }
    
    .letter-page h2 {
        font-size: 19px;
        margin-bottom: 15px;
    }
    
    .letter-page p {
        font-size: 14px;
        margin-bottom: 12px;
    }
}

/* 翻页动画 - 优化版本 */
.letter-page {
    /* Add will-change for better performance */
    will-change: transform, opacity;
}

.page-out {
    animation: pageOut 0.6s ease-in-out forwards;
}

.page-in {
    transform: translateX(100%);
    opacity: 0;
}

.page-in:not(.page-out) {
    /* Only apply the page-in animation if it's not also a page-out */
    animation: pageIn 0.6s ease-in-out forwards;
}

@keyframes pageOut {
    0% { 
        transform: translateX(0); 
        opacity: 1; 
    }
    100% { 
        transform: translateX(-100%); 
        opacity: 0; 
    }
}

@keyframes pageIn {
    0% { 
        transform: translateX(100%); 
        opacity: 0; 
    }
    100% { 
        transform: translateX(0); 
        opacity: 1; 
    }
}

/* 结尾区域雪花效果 */
#end-screen {
    overflow: hidden; /* 确保雪花动画在区域内 */
}