:root {
    --bg-color: #f7f8fa;
    --text-main: #2c3e50;
    --text-sub: #7f8c8d;
    --btn-dark: #1f2937;
    --btn-light: #ffffff;
    --btn-red: #e39393;
    --card-bg: #ffffff;
    --border-color: #f0f0f0;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    font-family: 'Noto Serif SC', 'Songti SC', 'STSong', '华文宋体', serif;
    color: var(--text-main);
    display: flex;
    justify-content: center;
    height: 100vh;
    overflow: hidden; /* 阻止 body 滚动，让内部元素滚动 */
}

#app {
    width: 100%;
    max-width: 480px;
    height: 100%;
    position: relative;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
}

.page {
    display: flex;
    flex-direction: column;
    padding: 40px 24px 20px 24px;
    height: 100%;
    box-sizing: border-box;
    animation: fadeIn 0.3s ease;
}

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

/* Home Page */
.home-title {
    text-align: center;
    font-size: 38px;
    margin-top: 60px;
    margin-bottom: 16px;
    font-weight: normal;
    letter-spacing: 2px;
}

.home-subtitle {
    text-align: center;
    color: var(--text-sub);
    font-size: 15px;
    margin-bottom: 60px;
    letter-spacing: 1px;
}

.btn {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    margin-bottom: 16px;
    font-family: inherit;
    border: none;
    outline: none;
    width: 100%;
    transition: opacity 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--btn-dark);
    color: #fff;
    box-shadow: 0 4px 12px rgba(31, 41, 55, 0.2);
}

.btn-secondary {
    background-color: var(--btn-light);
    color: var(--text-main);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
}

/* Select Movie Page */
.page-header {
    font-size: 24px;
    margin-bottom: 24px;
    font-weight: normal;
    flex-shrink: 0;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--text-main);
}

.search-box input::placeholder {
    color: #b2bec3;
}

.search-icon {
    color: #b2bec3;
    font-size: 18px;
}

/* 滚动列表容器 */
.movie-list-container {
    flex: 1; /* 占据中间所有剩余空间 */
    overflow-y: auto; /* 允许纵向滚动 */
    margin-bottom: 10px;
    padding-bottom: 10px;
}

/* 隐藏部分浏览器的滚动条或美化滚动条 */
.movie-list-container::-webkit-scrollbar {
    width: 4px;
}
.movie-list-container::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 4px;
}

.movie-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.movie-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.movie-card:active {
    border-color: #e0e0e0;
    transform: scale(0.98);
}

.movie-title {
    font-size: 18px;
    margin-bottom: 6px;
    color: var(--text-main);
}

.movie-meta {
    font-size: 14px;
    color: var(--text-sub);
}

.page-fab {
    position: fixed;
    right: 18px;
    bottom: 88px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #ffffff;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    z-index: 999;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.10);
}

.page-fab:active {
    transform: scale(0.96);
}

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.18);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.dialog-overlay.dialog-open {
    opacity: 1;
}

.dialog-overlay.dialog-closing {
    opacity: 0;
}

.dialog-card {
    width: 100%;
    max-width: 360px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.16);
    padding: 16px;
    transform: translateY(10px) scale(0.98);
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.dialog-overlay.dialog-open .dialog-card {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.dialog-overlay.dialog-closing .dialog-card {
    transform: translateY(10px) scale(0.98);
    opacity: 0;
}

.dialog-title {
    font-size: 15px;
    color: var(--text-main);
    margin-bottom: 12px;
}

.dialog-input {
    width: 100%;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 0 14px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    background: transparent;
    color: var(--text-main);
}

.dialog-actions {
    display: flex;
    gap: 12px;
    margin-top: 14px;
}

.dialog-btn {
    flex: 1;
    height: 44px;
    border-radius: 12px;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
    border: none;
    outline: none;
    transition: opacity 0.2s, transform 0.1s;
}

.dialog-btn:active {
    opacity: 0.85;
    transform: scale(0.98);
}

.dialog-cancel {
    background-color: var(--btn-light);
    color: var(--text-main);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
}

.dialog-confirm {
    background-color: var(--btn-dark);
    color: #fff;
    box-shadow: 0 4px 12px rgba(31, 41, 55, 0.2);
}

/* 底部按钮区，不被顶下去 */
.bottom-link {
    text-align: center;
    color: #9ca3af;
    font-size: 15px;
    padding: 16px 0;
    cursor: pointer;
    flex-shrink: 0; /* 防止被挤压 */
}

/* Write Letter Page */
.write-header {
    font-size: 22px;
    margin-bottom: 8px;
    line-height: 1.4;
    font-weight: normal;
    flex-shrink: 0;
}

.write-subtitle {
    font-size: 14px;
    color: var(--text-sub);
    margin-bottom: 24px;
    flex-shrink: 0;
}

.editor-container {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    display: flex;
    flex-direction: column;
    flex: 1; /* 文本框自适应占满剩余空间 */
    margin-bottom: 16px;
    min-height: 200px;
}

.editor-container textarea {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-main);
    font-family: inherit;
    resize: none;
    background: transparent;
}

.editor-container textarea::placeholder {
    color: #b2bec3;
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: var(--text-sub);
    padding: 0 4px;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.signature-action {
    color: #5a6a7c;
    margin-left: 8px;
    cursor: pointer;
}

.btn-submit {
    background-color: var(--btn-red);
    color: #fff;
    box-shadow: 0 4px 12px rgba(227, 147, 147, 0.3);
    transition: background-color 0.3s, box-shadow 0.3s;
}

.btn-submit.active {
    background-color: #c0392b; /* 深红色 */
    box-shadow: 0 4px 12px rgba(192, 57, 43, 0.4);
}

/* Modal Styles */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    text-align: center;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-icon {
    margin-bottom: 24px;
}

.modal-icon-emoji {
    font-size: 60px; /* 控制 Emoji 图标大小 */
    line-height: 1;
    margin-bottom: 24px;
    animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-title {
    font-size: 28px;
    font-weight: normal;
    margin-bottom: 16px;
    color: var(--text-main);
}

.modal-desc {
    font-size: 15px;
    color: var(--text-sub);
    line-height: 1.8;
    margin-bottom: 40px;
}

.modal-btn {
    width: 160px;
    border-radius: 12px; /* 和首页按钮圆角一致 */
}

/* Receive Letter Page */
.letter-display-container {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 30px 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    flex: 1; /* 自适应占据中间剩余空间 */
    margin-bottom: 24px;
    min-height: 200px;
}

.letter-content-text {
    font-size: 16px;
    line-height: 2;
    color: var(--text-main);
    letter-spacing: 0.5px;
}

.receive-tips {
    text-align: center;
    font-size: 14px;
    color: #9ca3af;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.btn-reply {
    background-color: #d32f2f; /* 偏红的颜色，类似图中的写回信按钮 */
    color: #fff;
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.3);
}

/* End Modal Specific Styles */
.quote-display {
    font-style: italic;
    color: #5a6a7c;
    font-size: 18px;
    line-height: 1.6;
    padding-left: 16px;
    border-left: 3px solid #5a6a7c;
    margin: 10px 0 40px 0;
    text-align: left;
    width: 80%;
    max-width: 280px;
}

.modal-btn-wide {
    width: 220px; /* 保存信件按钮稍微宽一些 */
}

.modal-bottom-link {
    margin-top: 10px;
    padding-bottom: 0;
}

/* Auth Pages (Login & Register) */
.form-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.input-group {
    width: 100%;
}

.auth-input {
    width: 100%;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    font-size: 16px;
    color: var(--text-main);
    font-family: inherit;
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.01);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input::placeholder {
    color: #b2bec3;
}

.auth-input:focus {
    border-color: #aeb6bf;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.captcha-group, .email-code-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.captcha-input, .email-code-input {
    flex: 1;
}

.captcha-img-box {
    width: 100px;
    height: 48px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    overflow: hidden;
}

.captcha-img-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-send-code {
    height: 48px;
    padding: 0 16px;
    border-radius: 12px;
    background-color: var(--btn-dark);
    color: #fff;
    font-size: 14px;
    border: none;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.2s, background-color 0.2s;
}

.btn-send-code:active {
    opacity: 0.8;
}

.btn-send-code:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    opacity: 1;
}

/* Mailbox Tabs */
.tabs-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    flex-shrink: 0;
}

.tab-item {
    padding: 12px 24px;
    font-size: 16px;
    color: var(--text-sub);
    cursor: pointer;
    position: relative;
    transition: color 0.3s;
}

.tab-item.active {
    color: var(--text-main);
    font-weight: bold;
}

.tab-item.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background-color: var(--btn-dark);
    border-radius: 3px;
}

.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    width: 100%;
    align-items: center;
}

.tab-content.active {
    display: flex;
}

/* Mailbox Scene (SVG) */
.mailbox-scene {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 40px;
    flex: 1;
}

.mailbox-wrapper {
    position: relative;
    width: 200px;
    height: 300px;
}

.mailbox-svg {
    width: 100%;
    height: 100%;
}

.mailbox-door {
    transition: transform 0.5s ease-in-out, opacity 0.5s;
    transform-origin: 60px 180px; /* 以门下沿为轴 */
}

.mailbox-letters {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.mailbox-flag {
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: 160px 118px; /* 绕圆心旋转 */
    cursor: pointer;
}

/* 状态控制 */
.mailbox-wrapper.closed .mailbox-door {
    transform: rotateX(0deg);
}

.mailbox-wrapper.closed .mailbox-flag {
    transform: rotate(0deg); /* 旗子平放 */
}

.mailbox-wrapper.open .mailbox-door {
    transform: translateY(20px) scaleY(0.1); /* 模拟门向下打开的透视效果 */
    opacity: 0.3;
}

.mailbox-wrapper.open .mailbox-flag {
    transform: rotate(-90deg); /* 旗子竖起 */
}

.mailbox-wrapper.open.has-letters .mailbox-letters {
    opacity: 1;
    transform: translateY(0);
}

.mailbox-hint {
    margin-top: 20px;
    font-size: 15px;
    color: var(--text-sub);
    letter-spacing: 1px;
}

.mail-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.22);
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.mail-detail-card {
    width: min(92vw, 420px);
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.20);
    padding: 18px 16px 16px;
    transform: translateY(14px) scale(0.96);
    opacity: 0;
    transition: transform 0.24s ease, opacity 0.24s ease;
}

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

.mail-detail-header-title {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: var(--text-sub);
    user-select: none;
}

.mail-detail-back,
.mail-detail-close {
    height: 32px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-main);
    font-size: 13px;
    cursor: pointer;
}

.mail-detail-back {
    visibility: hidden;
}

.mail-detail-view {
    width: 100%;
}

.mail-detail-content-view {
    display: none;
}

.mail-detail-card.show-content .mail-detail-content-view {
    display: block;
}

.mail-detail-card.show-content .mail-detail-list-view {
    display: none;
}

.mail-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 48vh;
    overflow-y: auto;
    padding-right: 2px;
}

.mail-list-item {
    padding: 12px 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: #fff;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.06);
}

.mail-list-item:active {
    transform: scale(0.99);
}

.mail-list-empty {
    text-align: center;
    color: var(--text-sub);
    padding: 28px 0 18px;
    font-size: 13px;
}

.mail-detail-card .movie-meta {
    margin: 10px 0 14px;
    line-height: 1.75;
    max-height: 42vh;
    overflow-y: auto;
    white-space: pre-wrap;
}

.mail-detail-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.mail-detail-overlay.open .mail-detail-card {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Debug Panel */
.debug-panel {
    position: fixed;
    left: 16px;
    top: 140px;
    padding: 14px;
    background-color: #fff;
    border-radius: 12px;
    border: 1px dashed #e2e8f0;
    width: 210px;
    z-index: 300;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

.debug-title {
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 10px;
    text-align: center;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.debug-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.debug-btn {
    padding: 8px;
    font-size: 13px;
    margin-bottom: 0;
    width: 100%;
}

.debug-btn.active {
    background-color: #cbd5e1;
    border-color: #cbd5e1;
}

/* Global Toast Notification */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    gap: 10px;
    width: 100%; /* 确保容器能居中并支持内部元素的 max-width */
}

.toast {
    max-width: 95%; /* 允许最大宽度为屏幕的95% */
    width: fit-content; /* 宽度根据内容自适应 */
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: toastFadeIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, 
               toastFadeOut 0.3s ease-out forwards 2.5s;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box; /* 确保 padding 包含在 width 内 */
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-text {
    line-height: 1.4;
    text-align: left;
    word-break: break-word; /* 允许在必要时换行 */
}

.toast.success {
    background-color: #10b981; /* 成功绿 */
}

.toast.error {
    background-color: #ef4444; /* 失败红 */
}

.toast.warning {
    background-color: #f59e0b; /* 警告黄 */
}

@keyframes toastFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}
