:root {
    --primary-color: rgba(134, 97, 255, 0.8);
    --secondary-color: rgba(88, 195, 255, 0.6);
    --glass-blur: blur(16px);
    --error-color: #ff2222;
    --success-color: #6cff89;
    --progress: 0%;
}

/* ========== Global Styles ========== */
body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(45deg, #2a2356, #1a3657, #0d2838);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-x: hidden;
    color: rgba(255, 255, 255, 0.95);
}

/* ========== Typography ========== */
h1, h2, h3 {
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    margin-top: 0;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: rgba(255, 255, 255, 0.9);
}

.particles {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: radial-gradient(circle,
    rgba(134, 97, 255, 0.1) 0%,
    rgba(88, 195, 255, 0.05) 100%
    );
}

/* ========== Home Button ========== */
.home-button {
    position: fixed;
    top: 20px;
    left: 20px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: var(--glass-blur);
    border-radius: 8px;
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.3s ease;
    z-index: 100;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.home-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    color: #ffffff;
}

.home-button svg {
    width: 1.2rem;
    height: 1.2rem;
}

/* ========== Main Container ========== */
.main-container {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: var(--glass-blur);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
    inset 0 4px 24px rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin: 2rem;
    width: 90%;
    max-width: 1600px;
    transition: transform 0.3s ease;
}

/* ========== App Container Layout ========== */
.app-container {
    display: flex;
    gap: 2rem;
    width: 100%;
}

.upload-container, .analysis-container {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* ========== Upload Section ========== */
.upload-section {
    margin-bottom: 1.5rem;
}

.drop-zone {
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

.drop-zone:hover {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.03);
}

.drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: rgba(255, 255, 255, 0.95);
}

.upload-icon {
    width: 64px;
    height: 64px;
    fill: rgba(255, 255, 255, 0.6);
    margin-bottom: 1rem;
}

.selected-files {
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    font-weight: 500;
}

/* ========== Input Group ========== */
.input-group {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

select {
    flex: 1;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 1rem;
    font-weight: 500;
    backdrop-filter: var(--glass-blur);
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem top 50%;
    background-size: 0.8rem auto;
    padding-right: 2.5rem;
}

select:focus {
    outline: 2px solid var(--primary-color);
    background-color: rgba(255, 255, 255, 0.15);
}

select option {
    background-color: #2a2356;
    color: white;
}

/* ========== Analyze Button ========== */
#analyzeBtn {
    padding: 1rem 1.5rem;
    font-size: 1rem;
    background: linear-gradient(135deg,
    var(--primary-color),
    var(--secondary-color));
    color: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    backdrop-filter: var(--glass-blur);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: filter 0.2s ease;
    position: relative;
    overflow: hidden;
    font-weight: 600;
    min-width: 150px;
    white-space: nowrap;
}

#analyzeBtn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

#analyzeBtn:hover:not(:disabled) {
    filter: brightness(1.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ========== Image Preview Section ========== */
.preview-container {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.image-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 0.5rem;
}

.image-preview {
    width: 120px;
    height: 150px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.image-preview:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border-color: var(--primary-color);
}

.image-preview img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.image-caption {
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 0.8rem;
    text-align: center;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-instruction, .zoom-instruction {
    text-align: center;
    font-size: 0.9rem;
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.7);
    font-style: italic;
}

/* ========== Analysis Results ========== */
.analysis-container {
    position: relative;
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.empty-icon {
    width: 80px;
    height: 80px;
    fill: rgba(255, 255, 255, 0.3);
    margin-bottom: 1rem;
}

.has-results .empty-state {
    opacity: 0;
    visibility: hidden;
}

.result-card {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    height: 100%;
    overflow-y: auto;
}

.has-results .result-card {
    opacity: 1;
    visibility: visible;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.status-indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #666;
}

.chart-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto;
}

.progress-circle {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1); /* Default background */
    position: relative;
    overflow: hidden;
}

.progress-circle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: conic-gradient(
            var(--primary-color) 0% var(--progress, 0%),
            transparent var(--progress, 0%) 100%
    );
    transform: rotate(-90deg); /* Start from top */
    transition: all 0.5s ease;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    text-align: center;
}

/* ========== Result Content ========== */
.result-content {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 2rem;
    align-items: center;
    margin-bottom: 2rem;
}

.result-details {
    display: grid;
    gap: 1rem;
}

.detail-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.detail-label {
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    font-weight: 600;
}

.detail-value {
    display: block;
    color: #ffffff;
    font-size: 1.2rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

/* ========== Performance Metrics ========== */
.performance-metrics {
    margin-bottom: 2rem;
}

.metrics-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.metric-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.metric-label {
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    font-weight: 600;
}

.metric-value {
    display: block;
    color: #ffffff;
    font-size: 1.2rem;
    margin-top: 0.5rem;
    font-weight: 500;
}

/* ========== Image Results ========== */
.raw-results h3 {
    color: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.image-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.image-result {
    text-align: center;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.image-result .result-code {
    font-size: 1.1rem;
    color: #ffffff;
    font-weight: 600;
    padding: 0.5rem;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
}

.image-result .result-code.good {
    background: rgba(108, 255, 137, 0.25);
}

.image-result .result-code.bad {
    background: rgba(255, 34, 34, 0.25);
}

.image-result .result-name {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.9rem;
    color: #ffffff;
    font-weight: 500;
}

.image-result .image-number {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
}

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

.image-modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#modalImage {
    max-width: 100%;
    max-height: 80vh;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    object-fit: contain;
    transition: transform 0.2s ease;
    cursor: move;
}

.close-modal {
    position: absolute;
    top: -40px;
    right: -40px;
    color: #fff;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    transition: transform 0.2s ease, background 0.2s ease;
}

.close-modal:hover {
    transform: scale(1.1);
    background: rgba(255, 0, 0, 0.7);
}

/* ========== Loading and Error Messages ========== */
.loading-dots {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.9);
    visibility: hidden;
}

.loading-dots::after {
    content: ".";
    animation: dots 1.5s infinite steps(3, end);
}

.error-message {
    color: var(--error-color);
    margin: 1rem 0;
    display: none;
    font-weight: 600;
    text-align: center;
    clear: both;
    background: rgba(255, 34, 34, 0.1);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 34, 34, 0.3);
}

@keyframes dots {
    0%, 20% {
        content: ".";
    }
    40% {
        content: "..";
    }
    60%, 100% {
        content: "...";
    }
}

/* ========== Responsive Design ========== */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
        align-items: center;
    }

    .upload-container, .analysis-container {
        width: 100%;
        min-height: 400px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .result-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-container {
        margin-bottom: 1.5rem;
    }

    .close-modal {
        top: -30px;
        right: -10px;
    }

    .main-container {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    .main-container {
        width: 95%;
        padding: 1rem;
    }

    .app-container {
        gap: 1rem;
    }

    .upload-container, .analysis-container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 1rem;
    }

    h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .metrics-container {
        grid-template-columns: 1fr;
    }

    .input-group {
        flex-direction: column;
    }

    .home-button {
        padding: 10px 16px;
    }

    .home-button span {
        display: none;
    }
}