/* 一拍成豆 - 移动端优先样式 */

/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
}

/* 应用容器 */
.app-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 步骤容器 */
.step {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.step.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(20px);
}

.step-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.step-header h2 {
    font-size: 18px;
    color: #333;
    flex: 1;
    text-align: center;
    margin: 0 20px;
}

.step-content {
    padding: 20px;
    padding-bottom: 100px;
}

/* 首页 Logo 区域 */
.logo {
    text-align: center;
    padding: 60px 20px 40px;
    color: white;
}

.logo-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.logo h1 {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.logo p {
    font-size: 16px;
    opacity: 0.9;
}

/* 上传区域 */
.upload-area {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px 20px;
    text-align: center;
    margin: 20px 0;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.upload-area:active {
    transform: scale(0.98);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.upload-icon {
    font-size: 60px;
    margin-bottom: 15px;
}

.upload-area p {
    font-size: 16px;
    color: #666;
}

/* 按钮样式 */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-width: 140px;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: white;
    color: #666;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn-large {
    width: 100%;
    padding: 18px 32px;
    font-size: 18px;
    margin-top: 20px;
}

.btn-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    padding: 0;
    gap: 0;
    font-size: 30px;
}

.btn-back {
    background: none;
    border: none;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.btn-back:active {
    background: rgba(0, 0, 0, 0.05);
}

.btn-restart {
    background: none;
    border: 1px solid #ddd;
    color: #666;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-restart:active {
    background: rgba(0, 0, 0, 0.05);
}

.btn-icon {
    font-size: 18px;
}

/* 按钮组 */
.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

/* 摄像头预览 */
.camera-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 1000;
}

.camera-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-preview .btn-circle {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
}

.camera-preview .btn-secondary {
    position: absolute;
    bottom: 60px;
    right: 20px;
    min-width: auto;
    padding: 12px 20px;
}

/* 预览图 */
.preview-container {
    width: 100%;
    max-width: 300px;
    margin: 0 auto 30px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.preview-image {
    width: 100%;
    height: auto;
    display: block;
}

/* 尺寸选择 */
.size-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.size-btn {
    flex: 1;
    min-width: 100px;
    max-width: 120px;
    background: white;
    border: 2px solid #eee;
    border-radius: 16px;
    padding: 20px 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.size-btn.selected {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.size-btn:active {
    transform: scale(0.96);
}

.size-label {
    font-size: 24px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 5px;
}

.size-value {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.size-desc {
    font-size: 12px;
    color: #999;
}

/* 图纸容器 */
.pattern-wrapper {
    width: 100%;
    height: 360px;
    overflow: hidden;
    position: relative;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    margin-bottom: 15px;
}

.pattern-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    transform-origin: center center;
}

#pattern-canvas {
    border-radius: 12px;
}

.zoom-reset-btn {
    display: block;
    margin: 0 auto 20px;
}

.pattern-info {
    text-align: center;
    margin-bottom: 20px;
}

#pattern-size-text {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    color: #666;
}

/* 材料清单 */
.material-list-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.material-list-container h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #333;
}

.material-list {
    max-height: 300px;
    overflow-y: auto;
}

.material-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

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

.material-color {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    margin-right: 12px;
    border: 1px solid #ddd;
}

.material-info {
    flex: 1;
}

.material-code {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.material-name {
    font-size: 12px;
    color: #999;
}

.material-count {
    font-size: 18px;
    font-weight: 700;
    color: #667eea;
}

/* 结果页按钮组 */
.result-actions {
    display: flex;
    gap: 15px;
}

.result-actions .btn {
    flex: 1;
}

/* Toast 通知 */
.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

.toast.error {
    background: #e74c3c;
}

.toast.success {
    background: #27ae60;
}

/* Loading 遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    font-size: 16px;
    color: #666;
}

/* 背景标记区域 */
.bg-marker-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.bg-marker-title {
    font-size: 18px;
    margin-bottom: 8px;
    color: #333;
}

.bg-marker-desc {
    font-size: 14px;
    color: #999;
    margin-bottom: 15px;
}

/* 已标记颜色列表 */
.marked-colors-list {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.no-marked {
    font-size: 14px;
    color: #999;
    text-align: center;
    padding: 10px;
}

.marked-color-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    margin-bottom: 8px;
}

.marked-color-item:last-child {
    margin-bottom: 0;
}

.marked-color-preview {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    margin-right: 12px;
    border: 1px solid #ddd;
}

.marked-color-text {
    flex: 1;
    font-size: 14px;
    color: #666;
}

.btn-remove-color {
    width: 28px;
    height: 28px;
    border: none;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.btn-remove-color:active {
    background: #c0392b;
}

/* 阈值控制 */
.threshold-control {
    margin-bottom: 15px;
}

.threshold-label {
    display: block;
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
}

.threshold-label span {
    color: #667eea;
    font-weight: 600;
}

.slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #ddd;
    border-radius: 3px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

/* 背景标记操作按钮 */
.bg-marker-actions {
    display: flex;
    gap: 10px;
}

.btn-small {
    padding: 10px 16px;
    font-size: 14px;
    min-width: auto;
}

/* 颜色选择面板 */
.color-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
    padding: 15px 20px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
    z-index: 1000;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.color-panel.hidden {
    transform: translateY(100%);
    opacity: 0;
}

.color-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.selected-cell-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#selected-cell-coord {
    font-size: 14px;
    color: #666;
}

#selected-cell-color {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.btn-close-color-panel {
    width: 32px;
    height: 32px;
    border: none;
    background: #f0f0f0;
    color: #666;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-close-color-panel:active {
    background: #ddd;
    transform: scale(0.95);
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.color-swatch {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 2px solid #eee;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

.color-swatch:active {
    transform: scale(0.92);
    border-color: #667eea;
}

.color-swatch:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.color-swatch-code {
    font-size: 10px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.7);
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
    pointer-events: none;
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 响应式调整 */
@media (max-width: 480px) {
    .step-content {
        padding: 15px;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        max-width: 300px;
    }
    
    .size-btn {
        min-width: 80px;
        padding: 15px 10px;
    }
    
    .size-value {
        font-size: 16px;
    }
}