:root {
    --bg-light: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --primary: #ec4899; /* Pink */
    --primary-hover: #db2777;
    --secondary: #3b82f6; /* Blue */
    --text-main: #1e293b; /* Dark text for light mode */
    --text-muted: #64748b;
    --success: #10b981;
    --glass-border: rgba(0, 0, 0, 0.05);
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: relative;
    overflow-x: hidden;
}

/* Background Animation */
.background-animation {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.15) 0%, rgba(255, 255, 255, 0) 50%),
                radial-gradient(circle at 80% 20%, rgba(59, 130, 246, 0.15) 0%, rgba(255, 255, 255, 0) 50%);
    animation: rotate 20s linear infinite;
    z-index: -1;
}

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

.container {
    max-width: 800px;
    width: 100%;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 3rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

header {
    text-align: center;
}

.logo-text {
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-main);
    margin-bottom: 1rem;
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border: 2px solid var(--text-main);
    border-radius: 4px;
}

.badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: rgba(236, 72, 153, 0.1);
    color: var(--primary);
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    border: 1px solid rgba(236, 72, 153, 0.2);
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.highlight {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Camera Section */
.camera-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.camera-wrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 3/4;
    border-radius: 20px;
    overflow: hidden;
    background: #e2e8f0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror effect */
}

.camera-corners span {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid var(--primary);
    border-radius: 8px;
    z-index: 10;
}

.camera-corners span:nth-child(1) { top: 20px; left: 20px; border-right: none; border-bottom: none; }
.camera-corners span:nth-child(2) { top: 20px; right: 20px; border-left: none; border-bottom: none; }
.camera-corners span:nth-child(3) { bottom: 20px; left: 20px; border-right: none; border-top: none; }
.camera-corners span:nth-child(4) { bottom: 20px; right: 20px; border-left: none; border-top: none; }

.scanner-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--secondary);
    box-shadow: 0 0 20px var(--secondary), 0 0 40px var(--secondary);
    opacity: 0;
    z-index: 5;
}

.scanning .scanner-line {
    animation: scan 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    opacity: 0.8;
}

@keyframes scan {
    0% { top: 0; }
    50% { top: 100%; }
    100% { top: 0; }
}

.primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 9999px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 20px rgba(236, 72, 153, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(236, 72, 153, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.primary-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.75rem 2rem;
    border-radius: 9999px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    background: rgba(236, 72, 153, 0.05);
}

.spinner {
    display: none;
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: white;
    padding: 2.5rem;
    border-radius: 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.modal-icon {
    width: 64px;
    height: 64px;
    background: rgba(236, 72, 153, 0.1);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content h2 {
    color: var(--text-main);
    font-size: 1.5rem;
    margin: 0;
}

.modal-content p {
    color: var(--text-muted);
    font-size: 1rem;
    margin: 0;
}

/* Results Section */
.results-section {
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.results-section.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
    justify-items: center;
    margin-top: 2rem;
}

.result-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 1;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--glass-border);
    animation: fadeIn 0.5s ease backwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.result-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.result-card:hover img {
    transform: scale(1.1);
}

.match-percentage {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    padding: 1.5rem 0.5rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.match-value {
    color: var(--success);
    font-weight: 800;
    font-size: 1.2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.match-label {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.9);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.download-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary);
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
    z-index: 10;
}

.download-btn:hover {
    background: white;
    transform: scale(1.05);
}

@media (max-width: 600px) {
    body {
        padding: 1rem;
        align-items: flex-start; /* Ensures content doesn't hide behind mobile browser bars */
    }

    .container {
        padding: 1.5rem 1rem;
        border-radius: 16px;
        gap: 1.5rem;
        margin-top: 1rem;
    }
    
    h1 {
        font-size: 1.8rem;
    }

    header p {
        font-size: 1rem;
    }

    .camera-wrapper {
        border-radius: 16px;
    }

    .primary-btn {
        width: 100%;
        font-size: 1.05rem;
    }
    
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 1rem;
        margin-top: 1rem;
    }

    .modal-content {
        padding: 1.5rem;
        border-radius: 16px;
        gap: 1rem;
    }

    .modal-icon {
        width: 48px;
        height: 48px;
    }

    .modal-icon svg {
        width: 24px;
        height: 24px;
    }

    .modal-content h2 {
        font-size: 1.3rem;
    }

    .close-viewer-btn {
        top: 10px;
        right: 15px;
        font-size: 2.5rem;
    }

    .image-viewer img {
        max-width: 95%;
    }

    .match-percentage {
        padding: 1rem 0.5rem 0.4rem;
    }

    .match-value {
        font-size: 1rem;
    }

    .download-btn {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }
}

/* Image Viewer Modal */
.image-viewer {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.image-viewer.hidden {
    opacity: 0;
    pointer-events: none;
}

.image-viewer img {
    max-width: 90%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
}

.close-viewer-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    background: none;
    border: none;
    color: white;
    font-size: 3rem;
    cursor: pointer;
    z-index: 2010;
    line-height: 1;
}

.close-viewer-btn:hover {
    color: var(--primary);
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-light);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner-large {
    width: 64px;
    height: 64px;
    border: 6px solid rgba(236, 72, 153, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 2rem;
}

.loading-screen h2 {
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.loading-screen p {
    color: var(--text-muted);
}
