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

:root {
    --primary-color: #1890ff;
    --primary-hover: #40a9ff;
    --secondary-color: #6c757d;
    --success-color: #52c41a;
    --warning-color: #faad14;
    --danger-color: #ff4d4f;
    --text-color: #262626;
    --text-secondary: #8c8c8c;
    --border-color: #d9d9d9;
    --bg-color: #f5f5f5;
    --white: #ffffff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary-color), #764ba2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 24px;
    font-weight: bold;
}

.logo-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);
}

.header-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 14px;
}

.main-content {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.upload-section {
    margin-bottom: 24px;
}

.recognition-type-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-color);
    border-radius: var(--radius);
}

.recognition-type-selector label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
}

.type-select {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--white);
    color: var(--text-color);
    cursor: pointer;
    transition: var(--transition);
    min-width: 160px;
}

.type-select:hover {
    border-color: var(--primary-color);
}

.type-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-color);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: #e6f7ff;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    color: var(--text-secondary);
}

.upload-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-secondary);
}

.preview-area {
    text-align: center;
}

.image-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 16px;
}

.image-preview img {
    max-width: 100%;
    max-height: 400px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--white);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.preview-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.result-section {
    display: none;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.result-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.result-actions {
    display: flex;
    gap: 12px;
}

.result-content {
    display: grid;
    gap: 24px;
}

.result-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
}

.image-card {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.image-card h3 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.image-card img {
    max-width: 100%;
    max-height: 250px;
    border-radius: var(--radius);
}

.result-info {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 24px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.info-item {
    text-align: center;
    padding: 16px;
    background: var(--white);
    border-radius: var(--radius);
}

.info-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.info-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
}

.info-value.confidence {
    color: var(--success-color);
}

.info-value.printed {
    color: var(--primary-color);
}

.info-value.handwritten {
    color: var(--warning-color);
}

.quality-info h3 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.quality-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.quality-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger-color), var(--warning-color), var(--success-color));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.quality-details {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

.result-text {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 24px;
}

.result-text h3,
.result-regions h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-color);
}

.text-container {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border-color);
    max-height: 300px;
    overflow-y: auto;
}

.text-container p {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.8;
}

.result-regions {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 24px;
}

.regions-list {
    display: grid;
    gap: 12px;
}

.region-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: var(--transition);
}

.region-item:hover {
    box-shadow: var(--shadow);
}

.region-number {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.region-content {
    flex: 1;
    min-width: 0;
}

.region-text {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    word-break: break-word;
}

.region-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.region-type {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.region-type.printed {
    background: #e6f7ff;
    color: var(--primary-color);
}

.region-type.handwritten {
    background: #fffbe6;
    color: var(--warning-color);
}

.region-type.math {
    background: #f9f0ff;
    color: #722ed1;
}

.features-section {
    background: var(--white);
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.features-section h2 {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 32px;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
}

.feature-card {
    text-align: center;
    padding: 24px;
    border-radius: var(--radius);
    transition: var(--transition);
}

.feature-card:hover {
    background: var(--bg-color);
}

.feature-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    color: var(--primary-color);
}

.feature-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.feature-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.footer {
    text-align: center;
    padding: 24px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-color);
    color: var(--white);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

.answer-preview-inner {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.answer-preview-inner img {
    display: block;
    max-width: 100%;
    height: auto;
    vertical-align: top;
}

.answer-region-canvas {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    cursor: crosshair;
    touch-action: none;
}

.answer-region-toolbar {
    margin-top: 16px;
    padding: 14px 16px;
    background: #f8f9ff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

.checkbox-inline input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.answer-region-qbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.answer-region-qbar .region-q-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--white);
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.answer-region-qbar .region-q-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.answer-region-qbar .region-q-btn.active {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .header {
        flex-direction: column;
        text-align: center;
    }
    
    .header-title h1 {
        font-size: 20px;
    }
    
    .preview-actions {
        flex-direction: column;
    }
    
    .result-header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }
    
    .result-actions {
        justify-content: center;
    }
    
    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .quality-details {
        flex-direction: column;
        gap: 8px;
    }
}
