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

body {
    font-family: Arial, sans-serif;
    background-color: #000;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

.camera-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 确保容器能够正确显示视频 */
    overflow: hidden;
    /* 确保容器占据整个视口 */
    min-height: 100vh;
    min-width: 100vw;
}

/* 视频预览区域 */
#video {
    /* 固定尺寸，确保完整显示 */
    width: 100%;
    height: 100%;
    /* 使用cover填满屏幕，但保持原始比例 */
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    /* 确保视频元素在最底层 */
    z-index: 1;
    /* 确保视频显示 */
    display: block;
    /* 硬件加速 */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* 确保背景为黑色 */
    background-color: black;
}

/* 错误提示 */
.error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    max-width: 80%;
    z-index: 300;
    display: none;
    word-break: break-all;
}

/* 相机控制区域 */
.camera-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    min-height: 200px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    display: flex;
    flex-direction: column; /* 垂直排列 */
    align-items: center;
    justify-content: center; /* 垂直居中 */
    padding: 20px 0;
    /* 适配iOS安全区域，防止被底部导航栏遮挡 */
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-bottom: calc(20px + constant(safe-area-inset-bottom));
    z-index: 50;
    gap: 15px; /* 按钮间距 */
}

/* 相机选择按钮样式 */
.camera-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    flex-direction: row; /* 确保横向排列 */
    width: auto !important; /* 覆盖默认固定宽度 */
    min-width: 80px; /* 确保有足够宽度显示文本 */
    border-radius: 25px; /* 使用圆角矩形，更适合文本显示 */
    background-color: rgba(255, 255, 255, 0.3); /* 确保背景色正确 */
}

.camera-btn span {
    font-size: 14px;
    font-weight: bold;
    color: white !important; /* 确保文本为白色 */
    writing-mode: horizontal-tb; /* 确保横向书写 */
    text-orientation: initial; /* 重置文本方向，确保横向显示 */
    margin-right: 5px; /* 与图标保持适当间距 */
    white-space: nowrap; /* 禁止文本换行 */
    display: inline-block; /* 确保文本作为块级元素横向排列 */
}

/* 确保按钮内所有文本元素都是白色 */
.camera-btn * {
    color: white !important;
    white-space: nowrap; /* 禁止所有元素换行 */
}

/* 调整控制按钮样式，确保相机按钮有足够宽度 */
.control-btn.camera-btn {
    width: auto !important; /* 覆盖默认固定宽度 */
    min-width: 80px; /* 确保有足够宽度显示文本 */
    border-radius: 25px; /* 使用圆角矩形 */
    padding: 0 15px; /* 增加内边距 */
}

/* 相机选择容器，用于定位下拉菜单 */
.camera-select-container {
    position: relative;
    display: inline-block;
    margin-bottom: 15px; /* 增加与拍照按钮的间距 */
}

/* 相机选择下拉菜单 */
.camera-dropdown {
    position: absolute;
    bottom: 120%; /* 相对于相机选择按钮定位 */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    z-index: 100;
    min-width: 120px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 300px;
    overflow-y: auto;
    display: none; /* 默认隐藏 */
}

/* 确保下拉菜单在打开时显示 */
.camera-dropdown[style*="display: block"] {
    display: block !important;
}

/* 相机选择选项 */
.camera-options {
    display: flex;
    flex-direction: column;
    padding: 5px;
}

.camera-option {
    padding: 12px 20px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 10px;
    text-align: center;
    transition: all 0.2s ease;
    border: none;
    background: transparent;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.camera-option:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.camera-option.active {
    background-color: rgba(255, 255, 255, 0.3);
}

.control-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    color: white; /* 确保按钮文本为白色 */
    text-decoration: none;
}

/* 相机选择按钮特殊样式，确保覆盖默认控制按钮样式 */
.control-btn.camera-btn {
    width: auto !important; /* 必须使用!important覆盖默认固定宽度 */
    min-width: 80px;
    border-radius: 25px !important; /* 使用圆角矩形 */
    padding: 0 15px;
    height: 60px;
    background-color: rgba(255, 255, 255, 0.3);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-direction: row !important;
}

.control-btn.camera-btn span {
    font-size: 14px !important;
    font-weight: bold !important;
    color: white !important;
    writing-mode: horizontal-tb !important;
    text-orientation: initial !important;
    margin-right: 5px !important;
    white-space: nowrap !important;
    display: inline-block !important;
}

.control-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

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

.control-btn svg {
    width: 30px;
    height: 30px;
}

/* 拍照按钮特殊样式 */
.capture-btn {
    width: 80px;
    height: 80px;
    background-color: transparent;
    border: 3px solid white;
}

.capture-inner {
    width: 70px;
    height: 70px;
    background-color: white;
    border-radius: 50%;
    margin: 0 auto;
}

/* 闪光灯按钮激活状态 */
.flash-btn.active {
    background-color: rgba(255, 255, 0, 0.5);
}

/* 照片预览区域 */
.photo-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    display: none;
}

#captured-photo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 预览控制按钮区域 */
.preview-controls {
    position: absolute;
    bottom: 30px;
    /* 适配iOS安全区域，防止被底部导航栏遮挡 */
    bottom: calc(30px + env(safe-area-inset-bottom));
    bottom: calc(30px + constant(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    gap: 25px;
    z-index: 100;
}

.preview-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.preview-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.preview-btn:active {
    transform: scale(0.95);
}

.save-btn {
    background-color: rgba(0, 200, 0, 0.6);
}

.save-btn:hover {
    background-color: rgba(0, 200, 0, 0.8);
}

/* 加载指示器样式 */
.loading-indicator {
    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 1s linear infinite;
    vertical-align: middle;
    margin: 0 auto;
}

/* 全屏加载指示器 */
.fullscreen-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    display: none;
}

.fullscreen-loading-indicator {
    width: 80px;
    height: 80px;
    border: 4px solid transparent;
    border-radius: 50%;
    border-top: 4px solid #4CAF50;
    border-right: 4px solid #4CAF50;
    animation: spin 1s linear infinite;
    position: relative;
}

.fullscreen-loading-indicator::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 4px solid transparent;
    border-top: 4px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: spin 0.8s linear reverse infinite;
}

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

/* 识别结果卡片样式 */
.recognition-result {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 80%;
    max-width: 320px;
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 1100;
    display: none;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    opacity: 0;
    animation: resultCardAppear 0.3s ease-out forwards;
}

/* 识别结果卡片出现动画 */
@keyframes resultCardAppear {
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
}

.close-result-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.close-result-btn:hover {
    background-color: #f5f5f5;
    color: #333;
}

.result-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.result-content {
    padding: 30px 25px;
    text-align: center;
}

.result-image-container {
    margin-bottom: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

#result-image {
    max-width: 200px;
    max-height: 200px;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.result-info {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.result-en-name {
    font-size: 30px;
    font-weight: 700;
    color: #222;
    margin: 0;
    letter-spacing: -0.5px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.result-cn-name {
    font-size: 22px;
    color: #444;
    margin: 0;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.phonetic-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 2px;
}

.result-phonetic {
    font-size: 16px;
    color: #666;
    margin: 0;
    font-style: italic;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 调整两个phonetic-container之间的间距 */
.result-info .phonetic-container + .phonetic-container {
    margin-top: 5px;
}

.speaker-icon {
    font-size: 16px;
    color: #4CAF50;
    cursor: pointer;
    transition: all 0.3s ease;
}

.speaker-icon:hover {
    transform: scale(1.1);
    color: #45a049;
}

/* 按钮加载状态 */
.preview-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.preview-btn:disabled:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.preview-btn.save-btn:disabled:hover {
    background-color: rgba(0, 200, 0, 0.6);
}

/* 确保按钮文本和加载指示器的容器大小固定 */
.preview-btn > span {
    display: inline-block;
    vertical-align: middle;
}

/* 确保按钮在禁用状态下大小不变 */
.preview-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 日志显示区域 */
.log-container {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 250px;
    max-height: 150px;
    background-color: rgba(0, 0, 0, 0.3);
    color: white;
    border-radius: 8px;
    overflow: hidden;
    z-index: 300;
    font-family: monospace;
    font-size: 10px;
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    /* 默认可见，便于调试 */
    display: flex;
    flex-direction: column;
}

.log-header {
    padding: 6px 10px;
    background-color: rgba(255, 255, 255, 0.1);
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.clear-log {
    font-size: 8px;
    cursor: pointer;
    color: #00ffff;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.clear-log:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.log-content {
    padding: 6px 10px;
    flex: 1;
    overflow-y: auto;
    line-height: 1.3;
    /* 防止日志内容换行 */
    white-space: nowrap;
}

.log-content::-webkit-scrollbar {
    width: 6px;
}

.log-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.log-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.log-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* 日志级别样式 */
.log-info {
    color: #00ffff;
}

.log-success {
    color: #00ff00;
}

.log-error {
    color: #ff0000;
}

.log-warning {
    color: #ffff00;
}

/* 后置摄像头切换按钮 */
.rear-camera-switch {
    position: absolute;
    bottom: 140px;
    right: 20px;
    z-index: 50;
}

.rear-camera-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background-color: rgba(255, 255, 255, 0.3);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.rear-camera-btn:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

.rear-camera-btn:active {
    transform: scale(0.95);
}

.rear-camera-btn svg {
    width: 20px;
    height: 20px;
}



/* 响应式设计 */
@media (orientation: landscape) {
    .camera-controls {
        height: 100px;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
    }
    
    .capture-btn {
        width: 70px;
        height: 70px;
    }
    
    .capture-inner {
        width: 60px;
        height: 60px;
    }
    
    .control-btn svg {
        width: 25px;
        height: 25px;
    }
    
    .log-container {
        width: 250px;
        max-height: 300px;
    }
    
    .rear-camera-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .rear-camera-btn svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 320px) {
    .camera-controls {
        height: 100px;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
    }
    
    .capture-btn {
        width: 70px;
        height: 70px;
    }
    
    .capture-inner {
        width: 60px;
        height: 60px;
    }
    
    .log-container {
        width: 200px;
        max-height: 250px;
        font-size: 10px;
    }
    
    .rear-camera-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .rear-camera-btn svg {
        width: 18px;
        height: 18px;
    }
}