/* --- 全局变量定义：默认(深夜主题) --- */
:root {
    --bg-color: #f4e1d2; /* 基础纸张色 */
    --bg-tint: rgba(30, 30, 40, 0.4); /* 叠加色调 */
    --wood-color: #3e2723; /* 深木色 */
    --accent-color: #d84315; /* 强调色 */
    --text-color: #2c1e19;
    --paper-line: #b0bec5; 
    --overlay-bg: #1a1a1a; /* 投递遮罩背景 */
}

/* --- 时段主题覆盖类 --- */

/* 清晨 (06:00 - 11:59) */
body.theme-morning {
    --bg-color: #fdfbf7;
    --bg-tint: rgba(173, 216, 230, 0.15); /* 淡淡的晨蓝 */
    --wood-color: #5d4037;
    --accent-color: #0277bd; /* 晨曦蓝 */
    --text-color: #37474f;
    --paper-line: #cfd8dc;
    --overlay-bg: #e1f5fe; /* 遮罩层亮色 */
}

/* 午后 (12:00 - 17:59) */
body.theme-afternoon {
    --bg-color: #fffde7;
    --bg-tint: rgba(255, 235, 59, 0.05); /* 温暖的阳光黄 */
    --wood-color: #4e342e;
    --accent-color: #f57f17; /* 活力橙 */
    --text-color: #212121;
    --paper-line: #dcedc8;
    --overlay-bg: #fff9c4;
}

/* 黄昏 (18:00 - 23:59) */
body.theme-evening {
    --bg-color: #fbe9e7;
    --bg-tint: rgba(255, 87, 34, 0.1); /* 晚霞红 */
    --wood-color: #3e2723;
    --accent-color: #bf360c; /* 深红 */
    --text-color: #4a148c; /* 紫调文字 */
    --paper-line: #ffccbc;
    --overlay-bg: #3e2723;
}

/* 深夜 (00:00 - 05:59) - 继承默认或更深 */
body.theme-night {
    --bg-color: #cfd8dc;
    --bg-tint: rgba(10, 10, 20, 0.5); /* 深邃蓝黑 */
    --wood-color: #263238;
    --accent-color: #ffab00; /* 灯火黄 */
    --text-color: #102027;
    --paper-line: #90a4ae;
    --overlay-bg: #000000;
}


body {
    font-family: "Songti SC", "SimSun", serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 1.5s ease, color 1.5s ease;
    position: relative;
    overflow-x: hidden;
}

/* --- 环境氛围层 --- */
.ambient-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    /* 基础纹理 */
    background-image: radial-gradient(var(--wood-color) 0.5px, transparent 0.5px);
    background-size: 30px 30px;
    opacity: 0.3;
}

/* 叠加色调 */
.ambient-layer::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-tint);
    transition: background 1.5s ease;
}

/* 时段特定动画特效 */

/* 1. 深夜：闪烁微尘 */
body.theme-night .ambient-layer::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.3;
    animation: twinkle 5s infinite alternate;
}
@keyframes twinkle {
    0% { opacity: 0.1; transform: translateY(0); }
    100% { opacity: 0.4; transform: translateY(-10px); }
}

/* 2. 午后：流云光影 */
body.theme-afternoon .ambient-layer::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 100%;
    background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.4) 50%, rgba(255,255,255,0) 100%);
    opacity: 0.3;
    animation: drift 20s linear infinite;
    transform: skewX(-20deg);
}
@keyframes drift {
    from { transform: translateX(-50%) skewX(-20deg); }
    to { transform: translateX(0%) skewX(-20deg); }
}

/* 3. 黄昏：脉冲光晕 */
body.theme-evening .ambient-layer::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(to top, rgba(255, 87, 34, 0.2), transparent);
    animation: glow 4s infinite alternate;
}
@keyframes glow {
    from { opacity: 0.3; }
    to { opacity: 0.6; }
}

/* 4. 清晨：上升雾气 */
body.theme-morning .ambient-layer::before {
    content: '';
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to top, rgba(255,255,255,0.6) 0%, transparent 60%);
    animation: mist 8s infinite alternate;
}
@keyframes mist {
    from { transform: translateY(10px); opacity: 0.5; }
    to { transform: translateY(0); opacity: 0.8; }
}


.container {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    position: relative;
    z-index: 5;
}

/* --- 头部 --- */
header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--wood-color);
    padding-bottom: 20px;
    transition: border-color 1s;
}

h1 {
    font-size: 2.5em;
    color: var(--wood-color);
    margin: 10px 0;
    text-shadow: 2px 2px 0px rgba(255,255,255,0.3);
}

.hidden {
    display: none !important;
}

/* --- 按钮样式 --- */
button {
    background-color: var(--wood-color);
    color: #fff;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1em;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

button:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

.big-btn {
    font-size: 1.2em;
    padding: 15px 40px;
    margin: 20px 0;
    display: block;
    width: 100%;
}

.secondary-btn {
    background-color: #8d6e63; /* 默认备选色 */
    filter: grayscale(0.3);
}

/* 朗读按钮 */
.tts-btn {
    background-color: transparent;
    color: var(--wood-color);
    border: 1px solid var(--wood-color);
    padding: 5px 10px;
    font-size: 0.9em;
    margin-top: 10px;
    box-shadow: none;
    opacity: 0.7;
}

.tts-btn:hover {
    background-color: var(--wood-color);
    color: #fff;
    opacity: 1;
}

/* --- 表单与盒子容器 --- */
.auth-box, .welcome-card {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(93, 64, 55, 0.15);
    margin-bottom: 20px;
    backdrop-filter: blur(5px);
}

input, select {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-family: inherit;
    background-color: #fff;
}
input:focus, select:focus {
    border-color: var(--wood-color);
    outline: none;
}

/* --- 写信信纸效果 --- */
.paper {
    background: #fffcf5;
    padding: 30px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    position: relative;
    /* 线性渐变模拟信纸横线 */
    background-image: linear-gradient(var(--paper-line) 1px, transparent 1px);
    background-size: 100% 30px;
    line-height: 30px;
}

.paper-header {
    font-weight: bold;
    margin-bottom: 20px;
    font-size: 1.2em;
    color: var(--wood-color);
}

textarea {
    width: 100%;
    height: 300px;
    background: transparent;
    border: none;
    outline: none;
    font-size: 18px;
    line-height: 30px; /* 必须和背景线条对齐 */
    font-family: inherit;
    resize: none;
    color: var(--text-color);
}

.paper-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

/* --- 列表与回信 --- */
.letter-card {
    background: rgba(255, 255, 255, 0.9);
    border-left: 5px solid var(--wood-color);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.letter-meta {
    font-size: 0.8em;
    color: #888;
    margin-bottom: 10px;
}

.reply-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed #ccc;
    background: rgba(249, 249, 249, 0.5);
    padding: 15px;
}

.reply-content {
    white-space: pre-wrap;
    line-height: 1.6;
}

.locked-notice {
    color: var(--accent-color);
    font-weight: bold;
}

.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.nav a {
    text-decoration: underline;
    cursor: pointer;
    color: var(--wood-color);
}

/* =========================================
   沉浸式投递遮罩层 (适配主题)
   ========================================= */

#delivery-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg); /* 根据时间变化的背景 */
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: var(--text-color); /* 适配亮暗色 */
    transition: background 1.5s;
}

/* 如果是深夜或黄昏，强制白色文字以保证对比度 */
body.theme-night #delivery-overlay,
body.theme-evening #delivery-overlay {
    color: #fff;
}

/* 场景容器 */
.scene {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
}

/* --- 场景1: 行走动画 --- */
.walking-icon {
    font-size: 80px;
    margin-bottom: 30px;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

.walking-text {
    font-size: 1.2em;
    margin-bottom: 20px;
    opacity: 0.9;
    font-family: serif;
    min-height: 1.5em;
    text-align: center;
    max-width: 80%;
}

.progress-container {
    width: 60%;
    max-width: 300px;
    height: 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-color);
    transition: width 0.1s linear;
}

/* --- 场景2: 铁卷门与投递口 --- */
.shutter-door {
    width: 300px;
    height: 400px;
    background: repeating-linear-gradient(
        180deg,
        var(--wood-color),
        var(--wood-color) 20px,
        rgba(0,0,0,0.2) 20px,
        rgba(0,0,0,0.2) 22px
    );
    border: 10px solid var(--wood-color);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.8);
}

.mail-slot-label {
    background: #f4e1d2;
    padding: 5px 15px;
    margin-bottom: 20px;
    border: 2px solid var(--wood-color);
    color: #3e2723;
    font-weight: bold;
}

.mail-slot {
    width: 200px;
    height: 15px;
    background: #000;
    border-bottom: 2px solid #795548;
    position: relative;
    z-index: 2;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.mail-slot:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255,255,255,0.2);
}

.slot-opening {
    width: 100%;
    height: 100%;
}

.hand-pointer {
    position: absolute;
    top: 30px;
    width: 100%;
    text-align: center;
    font-size: 0.9em;
    color: inherit; /* 继承父级颜色 */
    opacity: 0.7;
    pointer-events: none;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 0.3; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-5px); }
}

.letter-envelope {
    font-size: 60px;
    position: absolute;
    bottom: -100px;
    transition: all 0.5s;
    z-index: 1;
}

@keyframes dropIn {
    0% { transform: translateY(200px) scale(1); opacity: 1; }
    50% { transform: translateY(0px) scale(0.8); opacity: 1; }
    100% { transform: translateY(-150px) scale(0.5); opacity: 0; }
}

.animate-drop {
    animation: dropIn 1.5s ease-in-out forwards;
}

/* --- 场景3: 确认弹窗 --- */
.confirm-modal {
    background: #fff;
    color: #333;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    max-width: 80%;
    width: 300px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 1px solid var(--wood-color);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.confirm-modal h3 {
    margin-top: 0;
    color: var(--accent-color);
}

.confirm-modal p {
    line-height: 1.6;
    color: #555;
    margin-bottom: 25px;
    font-size: 0.95em;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}