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

body {
    background: #f5f7fb;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    color: #1a2a3a;
    line-height: 1.5;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f5f7fb;
}

/* 顶部栏 - 手机优化 */
.top-bar {
    background: #ffffff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #e9ecef;
    gap: 10px;
    flex-wrap: wrap;
}

.back-btn {
    background: #f0f2f5;
    border: none;
    padding: 8px 14px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #2c3e50;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s;
}

.back-btn:active {
    background: #e4e6e9;
    transform: scale(0.96);
}

.type-switch {
    display: flex;
    background: #f0f2f5;
    border-radius: 30px;
    padding: 3px;
    gap: 3px;
}

.type-btn {
    padding: 6px 16px;
    border-radius: 28px;
    font-size: 0.8rem;
    font-weight: 600;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #6c7a8a;
    transition: all 0.2s;
}

.type-btn.active {
    background: #ffffff;
    color: #3b82f6;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.save-btn-top {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.save-btn-top:active {
    background: #2563eb;
    transform: scale(0.96);
}

.save-btn-top:disabled {
    opacity: 0.6;
    background: #94a3b8;
    transform: none;
}

/* 编辑区 */
.editor-area {
    flex: 1;
    padding: 20px 16px 30px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.letter-header {
    margin-bottom: 20px;
    text-align: center;
}

.letter-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1a2a3a;
}

.greeting {
    font-size: 0.95rem;
    color: #6c7a8a;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.user-info-display {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 16px;
    padding: 12px 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.user-info-label {
    font-size: 0.85rem;
    color: #6c7a8a;
}

.user-info-name {
    font-size: 0.9rem;
    color: #3b82f6;
    font-weight: 600;
    background: #eef2ff;
    padding: 4px 12px;
    border-radius: 20px;
}

/* 密钥结果卡片 - 保存后显示 */
.key-result-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 16px 20px;
    margin-bottom: 20px;
    display: none;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    animation: slideDown 0.3s ease;
}

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

.key-result-card.show {
    display: flex;
}

.key-info {
    flex: 1;
}

.key-label-small {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.7);
    letter-spacing: 1px;
}

.key-value-large {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 2px;
    color: white;
    word-break: break-all;
}

.copy-key-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 8px 16px;
    border-radius: 30px;
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-key-btn:active {
    background: rgba(255,255,255,0.3);
    transform: scale(0.96);
}

textarea {
    width: 100%;
    min-height: 280px;
    padding: 18px;
    font-size: 1rem;
    line-height: 1.6;
    font-family: -apple-system, BlinkMacSystemFont, 'Georgia', serif;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    background: #ffffff;
    resize: vertical;
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* 统一的选项面板 */
.options-panel {
    margin-top: 20px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

.option-row {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #e9ecef;
}

.option-row:last-child {
    border-bottom: none;
}

.option-row:active {
    background: #f8f9fa;
}

.option-row input {
    width: 22px;
    height: 22px;
    margin: 0;
    accent-color: #3b82f6;
    flex-shrink: 0;
}

.option-row label {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    color: #2c3e50;
}

.option-row small {
    display: block;
    font-size: 0.7rem;
    color: #8a9bb0;
    font-weight: normal;
    margin-top: 4px;
}

/* 私密信特有提示 */
.private-badge {
    background: #fefce8;
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #854d0e;
    border: 1px solid #fde047;
}

.word-count {
    text-align: right;
    font-size: 0.7rem;
    color: #8a9bb0;
    margin-top: 12px;
    font-weight: 500;
}

/* 模态框 - 手机优化 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 28px;
    padding: 24px 20px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
    font-size: 1.3rem;
    color: #1a2a3a;
    margin-bottom: 16px;
}

.modal-key {
    background: #f0f2f5;
    padding: 14px;
    border-radius: 16px;
    font-family: monospace;
    font-weight: 700;
    font-size: 1.3rem;
    letter-spacing: 3px;
    margin: 16px 0;
    color: #2c3e50;
}

.modal-url {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 14px;
    font-size: 0.7rem;
    word-break: break-all;
    margin: 12px 0;
    color: #6c7a8a;
}

.public-success-badge {
    background: #ecfdf5;
    color: #047857;
    padding: 10px;
    border-radius: 14px;
    font-size: 0.8rem;
    margin: 12px 0;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: 40px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: 0.2s;
    font-size: 0.9rem;
}

.modal-btn:active {
    transform: scale(0.97);
}

.modal-btn-primary {
    background: #3b82f6;
    color: white;
}

.modal-btn-secondary {
    background: #f0f2f5;
    color: #2c3e50;
}

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 0.85rem;
    z-index: 1100;
    max-width: 85%;
    text-align: center;
    line-height: 1.4;
}

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
    margin-right: 6px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 附件上传区域 */
.attachments-panel {
    margin-top: 20px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

.attach-row {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #e9ecef;
}

.attach-row:last-child {
    border-bottom: none;
}

.attach-row:active {
    background: #f8f9fa;
}

.attach-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.attach-icon.image { background: #eef2ff; color: #6366f1; }
.attach-icon.audio { background: #fef3c7; color: #f59e0b; }

.attach-label {
    flex: 1;
    font-weight: 500;
    font-size: 0.9rem;
    color: #2c3e50;
}

.attach-label small {
    display: block;
    font-size: 0.7rem;
    color: #8a9bb0;
    font-weight: normal;
    margin-top: 2px;
}

.attach-status {
    font-size: 0.75rem;
    color: #8a9bb0;
}

/* 图片预览网格 */
.image-previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
}

.image-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-attach {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.image-preview-item .upload-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #e2e8f0;
}

.image-preview-item .upload-progress-bar {
    height: 100%;
    background: #3b82f6;
    transition: width 0.3s;
}

/* 音频预览列表 */
.audio-previews {
    padding: 8px 16px;
    border-bottom: 1px solid #e9ecef;
}

.audio-preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f2f5;
}

.audio-preview-item:last-child {
    border-bottom: none;
}

.audio-preview-item audio {
    flex: 1;
    height: 32px;
}

.audio-preview-item .remove-attach {
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.7rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-filename {
    font-size: 0.75rem;
    color: #6c7a8a;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 550px) {
    .top-bar { padding: 10px 12px; gap: 8px; }
    .back-btn { padding: 6px 12px; font-size: 0.8rem; }
    .type-btn { padding: 5px 12px; font-size: 0.75rem; }
    .save-btn-top { padding: 6px 14px; font-size: 0.8rem; }
    .editor-area { padding: 16px 12px 25px; }
    .letter-header h2 { font-size: 1.3rem; }
    textarea { min-height: 250px; font-size: 0.95rem; padding: 14px; }
    .key-value-large { font-size: 1.1rem; }
    .key-result-card { padding: 12px 16px; }
    .copy-key-btn { padding: 6px 12px; font-size: 0.75rem; }
    .modal-content { padding: 20px 16px; }
    .modal-key { font-size: 1.1rem; padding: 10px; }
    .image-previews { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
    .audio-filename { max-width: 80px; }
}

/* ===== 上传进度弹窗 ===== */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    padding: 20px;
    animation: progressFadeIn 0.18s ease-out;
}

.progress-overlay.progress-closing {
    animation: progressFadeOut 0.2s ease-in forwards;
}

@keyframes progressFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes progressFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

.progress-card {
    background: #ffffff;
    border-radius: 24px;
    padding: 28px 24px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    text-align: center;
    animation: progressPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes progressPop {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.progress-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: #eef2ff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e0e7ff;
    border-top-color: #3b82f6;
    border-right-color: #3b82f6;
    border-radius: 50%;
    animation: progressSpin 0.8s linear infinite;
}

@keyframes progressSpin {
    to { transform: rotate(360deg); }
}

.progress-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1a2a3a;
    margin-bottom: 6px;
}

.progress-current {
    font-size: 0.78rem;
    color: #64748b;
    min-height: 1.2em;
    margin-bottom: 18px;
    word-break: break-all;
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #6366f1);
    border-radius: 999px;
    transition: width 0.2s ease;
}

.progress-percent {
    font-size: 0.85rem;
    font-weight: 600;
    color: #3b82f6;
    font-variant-numeric: tabular-nums;
}

.progress-tip {
    margin-top: 14px;
    font-size: 0.72rem;
    color: #94a3b8;
}

@media (max-width: 550px) {
    .progress-card {
        padding: 24px 18px 20px;
        border-radius: 20px;
    }
    .progress-title { font-size: 1rem; }
    .progress-current { font-size: 0.72rem; }
    .progress-icon { width: 50px; height: 50px; }
    .progress-spinner { width: 24px; height: 24px; }
}
