* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #000;
}

/* 相机视频背景 */
#camera-video {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    z-index: 1;
}

/* Three.js AR容器 */
#ar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
}

#ar-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* 加载屏幕 */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.loading-content {
    text-align: center;
    color: #fff;
}

.spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-content p {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.8);
}

/* 权限提示 */
#permission-prompt {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 101;
}

.permission-content {
    text-align: center;
    padding: 40px 30px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    max-width: 80%;
}

.permission-content h2 {
    font-size: 24px;
    color: #fff;
    margin-bottom: 15px;
}

.permission-content p {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 30px;
    line-height: 1.5;
}

#grant-permission-btn {
    padding: 15px 40px;
    font-size: 18px;
    color: #fff;
    background: linear-gradient(135deg, #d4145a 0%, #fbb03b 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: 600;
}

#grant-permission-btn:active {
    transform: scale(0.95);
}

/* 错误消息 */
#error-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 102;
}

.error-content {
    text-align: center;
    padding: 30px;
    background: rgba(255, 50, 50, 0.2);
    border-radius: 15px;
    max-width: 80%;
}

.error-content p {
    font-size: 16px;
    color: #fff;
    margin-bottom: 20px;
    line-height: 1.5;
}

#retry-btn {
    padding: 12px 30px;
    font-size: 16px;
    color: #fff;
    background: #d4145a;
    border: none;
    border-radius: 30px;
    cursor: pointer;
}

/* 调试信息 */
#debug-info {
    position: fixed;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 12px;
    font-family: monospace;
    z-index: 50;
    line-height: 1.6;
}

#debug-info p {
    margin: 3px 0;
}

#debug-info span {
    color: #4af;
    font-weight: bold;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .permission-content h2 {
        font-size: 20px;
    }
    
    .permission-content p {
        font-size: 14px;
    }
    
    #grant-permission-btn {
        padding: 12px 30px;
        font-size: 16px;
    }
}

/* 防止页面滚动和缩放 */
body {
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 全局禁用图片长按菜单 */
img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: auto;
}

/* 预览图片允许长按保存 */
#preview-image {
    -webkit-touch-callout: default;
    -webkit-user-select: auto;
    user-select: auto;
    -webkit-user-drag: none;
}

/* 祝福语区域背景层 */
#blessing-area-overlay {
    position: fixed;
    top: 9%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    pointer-events: none;
    overflow: hidden;
}

#blessing-area-img {
    display: block;
    width: 80vw;
    height: auto;
    pointer-events: none;
}

/* 装饰边框叠加层 */
#decorative-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 4;
    pointer-events: none;
    overflow: hidden;
}

#current-frame {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

/* 祝福语显示层 - 在祝福语区域内水平垂直居中 */
#blessing-display {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: 'STKaiti', 'KaiTi', 'STSong', 'SimSun', serif;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 8px rgba(0, 0, 0, 0.5);
    /* 宽度：占父容器85% */
    box-sizing: border-box;
    /* 字体大小：根据屏幕宽度自适应 */
    font-size: clamp(24px, 5vw, 48px);
    line-height: 1.4;
    word-wrap: break-word;
    overflow: hidden;
}

/* 控制按钮栏 */
#control-panel {
    position: fixed;
    bottom: 14vh;
    left: 0;
    width: 100%;
    z-index: 10;
}

.control-btn {
    width: min(60px, 8vw);
    height: min(60px, 8vw);
    min-width: 50px;
    min-height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    padding: 0;
    /* 移除iOS Safari默认按钮样式 */
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* 编辑祝福按钮 - 左边30像素，往上30像素 */
#text-input-btn {
    position: absolute;
    left: 50px;
    bottom: 60px;
}

/* 切换摄像头按钮 - 右边30像素，往上30像素 */
#switch-camera-btn {
    position: absolute;
    right: 50px;
    bottom: 60px;
}

/* 拍照按钮 - 中间，放大1.5倍 */
#capture-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) scale(1.5);
    bottom: 0;
}

#capture-btn:active {
    transform: translateX(-50%) scale(1.35);
}

/* 文字输入弹窗 */
#text-input-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    padding: min(30px, 4vw);
    border-radius: 20px;
    max-width: 90%;
    width: min(400px, 90vw);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h3 {
    color: #fbb03b;
    margin-bottom: 20px;
    text-align: center;
    font-size: clamp(20px, 5vw, 24px);
}

#blessing-text {
    width: 100%;
    height: 120px;
    padding: 15px;
    border: 2px solid #d4145a;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.95);
    font-size: 18px;
    resize: none;
    font-family: 'STKaiti', 'KaiTi', 'STSong', 'SimSun', serif;
    box-sizing: border-box;
}

.text-options {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.text-options label {
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.text-options input[type="range"] {
    flex: 1;
    margin: 0 10px;
}

.text-options input[type="color"] {
    width: 50px;
    height: 30px;
    border: 2px solid #d4145a;
    border-radius: 5px;
    cursor: pointer;
}

#font-size-value {
    color: #fbb03b;
    font-weight: bold;
    min-width: 40px;
}

.preset-messages {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.preset-btn {
    padding: 12px;
    background: rgba(212, 20, 90, 0.2);
    border: 1px solid #d4145a;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    font-family: 'STKaiti', 'KaiTi', 'STSong', 'SimSun', serif;
}

.preset-btn:active {
    background: rgba(212, 20, 90, 0.5);
}

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

.modal-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: opacity 0.2s;
}

#text-confirm-btn {
    background: linear-gradient(135deg, #d4145a 0%, #fbb03b 100%);
    color: #fff;
}

#text-cancel-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.modal-buttons button:active {
    opacity: 0.8;
}

/* 预览弹窗 */
#preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
}

.close-preview-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: none;
    font-size: 36px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 301;
    padding: 0;
}

.close-preview-btn:active {
    transform: scale(0.9);
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.3);
}

.preview-content {
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#preview-image {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.preview-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
    align-items: center;
}

.preview-save-hint {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    text-align: center;
    margin-bottom: 5px;
    font-weight: normal;
}

.save-btn-icon {
    width: min(90px, 12vw);
    height: min(90px, 12vw);
    min-width: 75px;
    min-height: 75px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    padding: 0;
    /* 移除iOS Safari默认按钮样式 */
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.save-btn-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.save-btn-icon:active {
    transform: scale(0.9);
    opacity: 0.8;
}

/* 成功提示 */
.success-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 40px;
    background: rgba(0, 0, 0, 0.9);
    color: #fbb03b;
    border-radius: 10px;
    font-size: 18px;
    z-index: 400;
    transition: opacity 0.3s;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    font-weight: bold;
}

/* 移动端适配 */
@media (max-width: 768px) {
    #blessing-display {
        font-size: clamp(20px, 6vw, 36px);
    }
    
    .control-btn {
        width: min(55px, 10vw);
        height: min(55px, 10vw);
    }
    
    .modal-content {
        padding: 20px;
    }
}

