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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
    padding: 15px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #fff;
    font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.section {
    background: #2d2d44;
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
}

.section.hidden {
    display: none;
}

.instructions {
    text-align: center;
    color: #aaa;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.hint {
    text-align: center;
    color: #666;
    margin-top: 15px;
    font-size: 0.9rem;
}

/* Upload section */
.upload-area {
    display: flex;
    justify-content: center;
}

input[type="file"] {
    background: #3d3d54;
    border: 2px dashed #555;
    border-radius: 8px;
    padding: 30px 40px;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

input[type="file"]:hover {
    border-color: #777;
    background: #454560;
}

input[type="file"]::file-selector-button {
    background: #4a4a6a;
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    color: #fff;
    cursor: pointer;
    margin-right: 15px;
    font-size: 14px;
}

input[type="file"]::file-selector-button:hover {
    background: #5a5a7a;
}

/* Progress bar */
.progress-bar {
    margin-bottom: 20px;
}

#progressText {
    display: block;
    text-align: center;
    margin-bottom: 10px;
    color: #aaa;
    font-size: 1rem;
}

.progress-track {
    background: #1a1a2e;
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #2e7d32, #4caf50);
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

/* Canvas */
.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a1a2e;
    border-radius: 8px;
    min-height: 300px;
    overflow: hidden;
}

#canvas {
    max-width: 100%;
    max-height: 60vh;
    cursor: crosshair;
    touch-action: none;
}

/* Navigation buttons */
.nav-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.nav-buttons button {
    padding: 12px 24px;
    font-size: 15px;
}

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

button {
    background: #4a4a6a;
    border: none;
    border-radius: 8px;
    padding: 14px 28px;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

button:hover:not(:disabled) {
    background: #5a5a7a;
}

button:active:not(:disabled) {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #2e7d32;
    padding: 16px 40px;
    font-size: 17px;
}

.btn-primary:hover:not(:disabled) {
    background: #388e3c;
}

.btn-download {
    background: #1565c0;
    padding: 16px 40px;
    font-size: 17px;
}

.btn-download:hover:not(:disabled) {
    background: #1976d2;
}

#nextBtn {
    background: #2e7d32;
}

#nextBtn:hover:not(:disabled) {
    background: #388e3c;
}

/* Summary */
.summary {
    text-align: center;
    padding: 20px;
    background: #1a1a2e;
    border-radius: 8px;
    margin-bottom: 10px;
}

#summaryText {
    font-size: 1.2rem;
    color: #4caf50;
}

/* Results grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.result-item {
    position: relative;
    background: #1a1a2e;
    border-radius: 8px;
    overflow: hidden;
}

.result-item img {
    width: 100%;
    height: auto;
    display: block;
}

.result-item .result-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 8px;
    font-size: 12px;
    text-align: center;
}

.result-item .download-single {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(21, 101, 192, 0.9);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    padding: 8px;
    cursor: pointer;
}

.result-item .download-single:hover {
    background: rgba(25, 118, 210, 1);
}

.result-item .download-single svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 46, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #444;
    border-top-color: #4caf50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading p {
    color: #aaa;
    font-size: 1.2rem;
}

/* Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.lightbox.hidden {
    display: none;
}

.lightbox img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    background: none;
    border: none;
    color: white;
    font-size: 40px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.lightbox-close:hover {
    color: #ff4444;
}

.lightbox-download {
    margin-top: 20px;
    background: #1565c0;
    color: white;
    padding: 14px 30px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 16px;
}

.lightbox-download:hover {
    background: #1976d2;
}

.result-item img {
    cursor: pointer;
}

/* Mobile */
@media (max-width: 600px) {
    .section {
        padding: 20px 15px;
    }

    .nav-buttons {
        flex-direction: column;
    }

    .nav-buttons button {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons button {
        width: 100%;
    }

    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    #canvas {
        max-height: 50vh;
    }
}
