html, body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    width: 100%;    
    -webkit-text-size-adjust: 100%;
}

.container {
    margin: 0 auto;
    text-align: left;
    padding: 0 10px;
    max-width: 1200px;
}

/* ===== 顶部 ===== */
h2 {
    text-align: left;
    color: #333;
    margin-bottom: 30px;
    font-size: clamp(18px, 4vw, 28px);
}

#description {
    padding: 0 10px;
    line-height: 1.8;
    text-align: left;    
}

/* ===== 头部 ===== */
.header {
    text-align: center;
}

.header h1 {
    font-size: clamp(24px, 5vw, 32px);
    background: linear-gradient(135deg, #4CAF50, #2196F3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header p {
    color: #888;
    margin-top: 8px;
    font-size: clamp(13px, 2vw, 16px);
}

/* ===== 卡片 ===== */
.card {
    background: white;
    border-radius: 16px;
    padding: 16px 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    margin-bottom: 16px;
}

@media (min-width: 768px) {
    .card {
        padding: 24px 30px;
    }
}

/* ===== 上传区域 ===== */
.upload-layout {
    display: flex;
    gap: 12px;
    align-items: stretch;
    max-height: none;
    flex-direction: column;
}

@media (min-width: 768px) {
    .upload-layout {
        flex-direction: row;
        max-height: 230px;
    }
    .upload-layout .drop-zone {
        flex: 1;
        min-height: 200px;
    }
    .upload-layout #previewArea {
        flex: 1;
        min-height: 200px;
    }
}

.upload-layout .drop-zone {
    flex: 1;
    min-height: 180px;
    padding: 16px 12px;
}

.upload-layout #previewArea {
    flex: 1;
    margin-top: 0;
    overflow: hidden;
    min-height: 180px;
    max-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 8px;
}

.upload-layout #previewArea:not(.hidden) {
    display: flex;
}

/* ===== 拖放区域 ===== */
.drop-zone {
    border: 3px dashed #ccc;
    border-radius: 16px;
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover {
    border-color: #4CAF50;
    background: #f0faf0;
}

.drop-zone.dragover {
    border-color: #4CAF50;
    background: #e8f5e9;
}

.drop-zone.has-image {
    padding: 10px;
}

.drop-zone .icon {
    font-size: 36px;
}

@media (min-width: 768px) {
    .drop-zone .icon {
        font-size: 48px;
    }
}

.drop-zone .text {
    font-size: clamp(14px, 2.5vw, 18px);
    color: #666;
    margin-top: 8px;
}

.drop-zone .hint {
    font-size: clamp(12px, 2vw, 14px);
    color: #999;
    margin-top: 4px;
}

/* ===== 预览区域 ===== */
#previewArea {
    margin-top: 12px;
    text-align: center;
    overflow: hidden;
    position: relative;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 8px;
    width: 100%;
    /* ===== 固定高度，让图片完全适配 ===== */
    height: 300px;
    max-height: 400px;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

@media (min-width: 768px) {
    #previewArea {
        height: 400px;
        max-height: 450px;
        min-height: 250px;
    }
}

@media (max-width: 480px) {
    #previewArea {
        height: 200px;
        max-height: 250px;
        min-height: 150px;
    }
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: contain;  /* ===== 关键：保持比例，完全可见 ===== */
    border-radius: 8px;
    transition: transform 0.3s ease;
    transform-origin: center center;
    display: block;
	max-height: 300px;
}

/* ===== 操作按钮 ===== */
.upload-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.upload-actions .btn {
    padding: 10px 18px;
    font-size: clamp(13px, 2vw, 16px);
}

/* ===== 通用按钮 ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: clamp(14px, 2.2vw, 16px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    touch-action: manipulation;
    min-height: 44px;
    justify-content: center;
}

@media (min-width: 768px) {
    .btn {
        padding: 12px 36px;
        min-height: auto;
    }
}

.btn-primary {
    background: linear-gradient(135deg, #4CAF50, #43A047);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: #e8ecf1;
    color: #555;
}

.btn-secondary:hover {
    background: #d5dbe3;
}

.btn-danger {
    background: #e53935;
    color: white;
}

.btn-danger:hover {
    background: #c62828;
}

.btn-success {
    background: linear-gradient(135deg, #43A047, #2E7D32);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46, 125, 50, 0.4);
}

.btn-sm {
    padding: 6px 12px;
    font-size: clamp(12px, 1.8vw, 13px);
    min-height: 36px;
}

.btn-zoom {
    padding: 6px 10px;
    font-size: clamp(12px, 1.8vw, 14px);
    border-radius: 6px;
    border: 1px solid #d0d7de;
    background: white;
    color: #333;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    min-height: 36px;
    min-width: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-zoom:hover {
    border-color: #2563EB;
    color: #2563EB;
    background: #f0f7ff;
}

.btn-zoom.active {
    border-color: #2563EB;
    background: #2563EB;
    color: white;
}

.file-name {
    color: #666;
    font-size: clamp(12px, 1.8vw, 14px);
    word-break: break-all;
}

.error-msg {
    background: #ffebee;
    color: #c62828;
    padding: 10px 16px;
    border-radius: 8px;
    margin-top: 12px;
    border-left: 4px solid #c62828;
    font-size: clamp(13px, 2vw, 15px);
}

/* ===== Loading ===== */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(76, 175, 80, 0.3);
    border-radius: 50%;
    border-top-color: #4CAF50;
    animation: spin 0.8s ease-in-out infinite;
    margin-right: 6px;
    vertical-align: middle;
}

@media (min-width: 768px) {
    .spinner {
        width: 20px;
        height: 20px;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== 标注工具栏 ===== */
.annotator-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.annotator-toolbar .info {
    margin-left: auto;
    font-size: clamp(12px, 1.8vw, 14px);
    color: #666;
    background: #f0f0f0;
    padding: 4px 12px;
    border-radius: 20px;
}

@media (max-width: 480px) {
    .annotator-toolbar {
        gap: 6px;
    }
    .annotator-toolbar .btn-sm {
        padding: 4px 10px;
        font-size: 12px;
    }
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: #f5f7fa;
    border-radius: 8px;
    border: 1px solid #e8ecf1;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .zoom-controls .btn-zoom {
        padding: 4px 8px;
        font-size: 12px;
        min-height: 30px;
        min-width: 30px;
    }
    .zoom-controls .zoom-level {
        font-size: 11px;
        min-width: 40px;
    }
}

.zoom-controls .zoom-level {
    font-size: clamp(11px, 1.6vw, 13px);
    color: #666;
    min-width: 40px;
    text-align: center;
}

/* ===== Canvas 包装 ===== */
.canvas-wrapper {
    position: relative;
    background: #fafafa;
    border-radius: 8px;
    overflow: auto;
    border: 1px solid #e8ecf1;
    cursor: crosshair;
    user-select: none;
    height: 70vh;
    max-height: 600px;
    min-height: 400px;
    touch-action: none;
}

@media (min-width: 768px) {
    .canvas-wrapper {
        height: 1000px;
        max-height: 1000px;
    }
}

.canvas-wrapper.canvas-pan {
    cursor: grab;
}

.canvas-wrapper.canvas-pan:active {
    cursor: grabbing;
}

.canvas-wrapper canvas {
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
}

.canvas-hint {
    text-align: center;
    padding: 8px;
    color: #999;
    font-size: clamp(11px, 1.6vw, 13px);
    background: #fafafa;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #e8ecf1;
    line-height: 1.6;
}

/* ===== 底部操作栏 ===== */
.annotator-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    gap: 8px;
    flex-wrap: wrap;
}

.annotator-footer .btn {
    flex: 1;
    min-width: 80px;
    padding: 10px 12px;
    font-size: clamp(12px, 1.8vw, 14px);
}

@media (min-width: 768px) {
    .annotator-footer .btn {
        flex: none;
        padding: 12px 36px;
        font-size: 16px;
    }
}

/* ===== 结果页 ===== */
.result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 768px) {
    .result-grid {
        grid-template-columns: 2fr 1fr;
        gap: 24px;
    }
}

.result-image {
    background: #fafafa;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
	height: 600px;        /* 新增 */
    max-height: 600px;  /* 新增 */
    min-height: 300px;   /* 新增 */
}

.result-image img {
    width: 100%;
    height: auto;
    display: block;
}

.result-list {
    max-height: 600px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
    .result-list {
        max-height: 1000px;
    }
}

.result-list h3 {
    margin-bottom: 12px;
    color: #333;
    font-size: clamp(16px, 2.5vw, 20px);
}

.char-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

@media (max-width: 480px) {
    .char-grid {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
    }
}

.char-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: #f5f7fa;
    border-radius: 6px;
    transition: background 0.2s;
    cursor: pointer;
    touch-action: manipulation;
}

.char-item:hover {
    background: #e8ecf1;
}

.char-item.highlight {
    background: #fff3cd;
    border: 2px solid #ffc107;
}

.char-index {
    color: #999;
    font-size: clamp(10px, 1.4vw, 12px);
    min-width: 22px;
}

.char-text {
    font-size: clamp(18px, 4vw, 24px);
    font-weight: 600;
    min-width: 24px;
    text-align: center;
    color: #2563EB;
}

.char-conf {
    font-size: clamp(10px, 1.4vw, 12px);
    color: #4CAF50;
    margin-left: auto;
}

.result-actions {
    margin-top: 16px;
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid #e8ecf1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.result-actions .btn {
    flex: 1;
    min-width: 80px;
    padding: 10px 14px;
    font-size: clamp(12px, 1.8vw, 14px);
    justify-content: center;
}

@media (min-width: 768px) {
    .result-actions .btn {
        flex: none;
        padding: 12px 36px;
        font-size: 16px;
    }
}

/* ===== 隐藏 ===== */
.hidden {
    display: none !important;
}

.loading-text {
    text-align: center;
    padding: 40px;
    color: #666;
}

/* ===== 结果缩放控制 ===== */
.result-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: #f5f7fa;
    border-radius: 8px;
    border: 1px solid #e8ecf1;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.result-zoom-controls .btn-zoom {
    padding: 4px 8px;
    font-size: clamp(11px, 1.6vw, 13px);
    min-height: 30px;
    min-width: 30px;
}

@media (min-width: 768px) {
    .result-zoom-controls .btn-zoom {
        padding: 6px 12px;
        min-height: 36px;
        min-width: 36px;
        font-size: 14px;
    }
}

.result-zoom-controls .zoom-level {
    font-size: clamp(11px, 1.6vw, 13px);
    color: #666;
    min-width: 36px;
    text-align: center;
}

/* ===== 颜色抠图按钮 ===== */
.btn-color-pick {
    transition: all 0.2s ease;
    font-weight: 500;
    padding: 4px 10px;
    font-size: clamp(12px, 1.8vw, 13px);
    min-height: 32px;
    touch-action: manipulation;
    border-radius: 6px;
    border: 2px solid;
}

.btn-color-pick:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.btn-color-pick.active {
    outline: 3px solid #2563EB;
    outline-offset: 2px;
}

/* ===== 识别消息 ===== */
#recognizeMessage {
    flex: 1;
    text-align: center;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: clamp(12px, 1.8vw, 14px);
    font-weight: 500;    
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    background: transparent;
    color: #666;
    word-break: break-word;
}

#recognizeMessage.info {
    background: #e3f2fd;
    color: #0d47a1;
    border: 1px solid #90caf9;
}

#recognizeMessage.success {
    background: #e8f5e9;
    color: #1b5e20;
    border: 1px solid #81c784;
}

#recognizeMessage.error {
    background: #ffebee;
    color: #ff0000;
    border: 1px solid #ef9a9a;
}

#recognizeMessage.warning {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
}

#recognizeMessage .highlight {
    font-weight: 700;
    color: #2563EB;
}

#recognizeMessage .highlight-success {
    color: #4CAF50;
}

#recognizeMessage .highlight-error {
    color: #d32f2f;
}

/* ===== 排版选择 ===== */
.annotator-toolbar select {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: clamp(12px, 1.8vw, 13px);
    min-height: 32px;
    max-width: 120px;
}

/* ===== 响应式：超小屏 ===== */
@media (max-width: 480px) {
    .card {
        padding: 12px 8px;
        border-radius: 12px;
    }
    
    .upload-actions {
        gap: 6px;
    }
    .upload-actions .btn {
        padding: 8px 12px;
        font-size: 12px;
        min-height: 36px;
    }
    
    .annotator-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .annotator-footer .btn {
        width: 100%;
        min-height: 44px;
    }
    
    .result-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .result-actions .btn {
        width: 100%;
        min-height: 44px;
    }
    
    .drop-zone {
        min-height: 140px;
        padding: 12px 8px;
    }
    .drop-zone .icon {
        font-size: 28px;
    }
    .drop-zone .text {
        font-size: 14px;
    }
    .drop-zone .hint {
        font-size: 12px;
    }
    
    #previewArea {
        min-height: 120px;
        max-height: 200px;
    }
    
    .canvas-wrapper {
        min-height: 300px;        
    }
    
    .char-grid {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
    }
    .char-item {
        padding: 4px 6px;
    }
    .char-text {
        font-size: 16px;
    }
    
    .btn-color-pick {
        padding: 3px 8px;
        font-size: 11px;
        min-height: 28px;
    }
    
    .annotator-toolbar {
        gap: 4px;
    }
    .annotator-toolbar .btn-sm {
        padding: 3px 8px;
        font-size: 11px;
        min-height: 28px;
    }
    
    .zoom-controls {
        padding: 2px 4px;
        gap: 2px;
    }
    .zoom-controls .btn-zoom {
        padding: 3px 6px;
        font-size: 11px;
        min-height: 26px;
        min-width: 26px;
    }
    .zoom-controls .zoom-level {
        font-size: 10px;
        min-width: 32px;
    }
}

/* ===== 全屏 Loading ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    flex-direction: column;
    backdrop-filter: blur(4px);
    padding: 20px;
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay .loader {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: #4CAF50;
    border-radius: 50%;
    animation: spin 0.8s ease-in-out infinite;
    margin-bottom: 16px;
}

@media (min-width: 768px) {
    .loading-overlay .loader {
        width: 60px;
        height: 60px;
    }
}

.loading-overlay .loading-text {
    color: white;
    font-size: clamp(16px, 3vw, 20px);
    font-weight: 500;
    text-align: center;
    line-height: 1.8;
}

.loading-overlay .loading-text .highlight {
    color: #4CAF50;
    font-weight: 700;
}

.loading-overlay .loading-text .time-estimate {
    color: #FFD700;
    font-size: clamp(18px, 3.5vw, 24px);
    font-weight: 700;
}

.loading-overlay .loading-sub {
    color: rgba(255, 255, 255, 0.6);
    font-size: clamp(12px, 2vw, 14px);
    margin-top: 8px;
}

.loading-overlay .progress-bar {
    width: 80%;
    max-width: 300px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin-top: 16px;
    overflow: hidden;
}

.loading-overlay .progress-bar .progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    border-radius: 2px;
    transition: width 0.5s ease;
}