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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

header h1 {
    font-size: 2.5em;
    color: #667eea;
    margin-bottom: 10px;
}

.subtitle {
    color: #666;
    font-size: 1.1em;
}

/* Upload Section */
.upload-section {
    margin-bottom: 40px;
}

.upload-area {
    border: 3px dashed #667eea;
    border-radius: 15px;
    padding: 60px 40px;
    text-align: center;
    background: #f8f9ff;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: #764ba2;
    background: #f0f2ff;
    transform: translateY(-2px);
}

.upload-area.drag-over {
    border-color: #764ba2;
    background: #e8ebff;
    transform: scale(1.02);
}

.upload-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.upload-area h2 {
    color: #333;
    margin-bottom: 10px;
}

.upload-area p {
    color: #666;
    margin-bottom: 20px;
}

/* Preview Section */
.preview-section {
    text-align: center;
    padding: 30px;
    background: #f8f9ff;
    border-radius: 15px;
    margin-top: 20px;
}

.preview-section h3 {
    color: #667eea;
    margin-bottom: 20px;
}

.canvas-container {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
}

#previewImage {
    max-width: 100%;
    max-height: 400px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: block;
}

#drawingCanvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    border-radius: 10px;
}

#drawingCanvas.drawing-mode {
    cursor: crosshair;
}

.drawing-tools {
    background: #f8f9ff;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.drawing-tools h4 {
    margin: 0 0 15px 0;
    color: #667eea;
}

.tool-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.tool-btn {
    padding: 10px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.tool-btn:hover {
    border-color: #667eea;
    background: #f0f2ff;
}

.tool-btn.active {
    border-color: #667eea;
    background: #667eea;
    color: white;
}

.tool-options {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.tool-options label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666;
}

.tool-options input[type="range"] {
    width: 100px;
}

.tool-options input[type="color"] {
    width: 50px;
    height: 30px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

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

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
}

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

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

.loading p {
    color: #666;
    font-size: 1.1em;
}

/* Results Section */
.results-section {
    margin-bottom: 40px;
}

.results-section h2 {
    color: #667eea;
    margin-bottom: 20px;
    text-align: center;
}

.results-info {
    text-align: center;
    margin-bottom: 30px;
    padding: 15px;
    background: #f8f9ff;
    border-radius: 10px;
}

.results-info p {
    color: #666;
    font-size: 1.1em;
}

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

.result-card {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    padding: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.result-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border-color: #667eea;
}

.result-card.top-match {
    border-color: #667eea;
    background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
}

.result-rank {
    display: inline-block;
    background: #667eea;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: 600;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.result-card.top-match .result-rank {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.result-image {
    width: 100%;
    height: 200px;
    object-fit: contain;
    border-radius: 10px;
    background: #f8f9ff;
    margin-bottom: 15px;
    padding: 10px;
}

.result-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.confidence-bar {
    margin-bottom: 15px;
}

.confidence-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: #666;
}

.confidence-value {
    font-weight: 600;
    color: #667eea;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 5px;
    transition: width 0.5s ease;
}

.detailed-scores {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.detailed-scores h4 {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
}

.score-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85em;
}

.score-label {
    color: #666;
}

.score-value {
    font-weight: 600;
    color: #667eea;
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.stat-value {
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 10px;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Footer */
footer {
    text-align: center;
    padding-top: 30px;
    border-top: 2px solid #f0f0f0;
    color: #666;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    header h1 {
        font-size: 2em;
    }

    .upload-area {
        padding: 40px 20px;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .preview-actions {
        flex-direction: column;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-card {
    animation: fadeIn 0.5s ease;
}

.result-card:nth-child(1) { animation-delay: 0.1s; }
.result-card:nth-child(2) { animation-delay: 0.2s; }
.result-card:nth-child(3) { animation-delay: 0.3s; }
.result-card:nth-child(4) { animation-delay: 0.4s; }
.result-card:nth-child(5) { animation-delay: 0.5s; }

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
}

.modal-content {
    background-color: #fff;
    margin: 2% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 30px;
    color: #2c3e50;
    text-align: center;
    font-size: 28px;
}

.close {
    color: #aaa;
    float: right;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close:hover,
.close:focus {
    color: #000;
}

.preprocess-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-top: 20px;
}

.preprocess-step {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.preprocess-step:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.preprocess-step h3 {
    margin: 0 0 15px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
}

.preprocess-step img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    border: 2px solid #e0e0e0;
    background: white;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        padding: 20px;
        margin: 5% auto;
    }
    
    .preprocess-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .modal-content h2 {
        font-size: 22px;
    }
}
