:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-color: #6200ea;
    --accent-hover: #7c43bd;
    --highlight-left: #4caf50;
    --highlight-right: #2196f3;
    --border-radius: 12px;
    --transition-speed: 0.3s;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    /* Prevent scrolling */
    display: flex;
    flex-direction: column;
}

.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 5px 15px;
    box-sizing: border-box;
    gap: 8px;
}

/* Compact Header */
header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #1e1e1e 0%, #252525 100%);
    padding: 5px 15px;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border: 1px solid #333;
}

header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.progress-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
}

.score-display {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

#completion-percentage {
    color: var(--text-primary);
    font-weight: 600;
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    border: 1px solid #333;
}

#progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-hover));
    box-shadow: 0 0 10px var(--accent-color);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#leaderboard-btn {
    padding: 6px 15px;
    font-size: 0.9rem;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    /* Important for flex child resize */
}

.split-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 10px;
    min-height: 0;
    min-width: 0;
}

.split-layout.side-by-side {
    flex-direction: row;
    align-items: stretch;
}

.main-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    gap: 8px;
}

.split-layout.side-by-side .main-group {
    width: 48%;
    min-width: 0;
    /* Leave room for gap */
}

.section-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1px;
    padding: 5px 0 5px 10px;
    border-left: 3px solid var(--accent-color);
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    line-height: 1.4;
}

/* Ensure labels have same height in side-by-side mode for box alignment */
.split-layout.side-by-side .section-label {
    min-height: 38px;
    display: flex;
    align-items: center;
}

/* Top Section: Source Image (50% height) */
.source-section {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    min-height: 0;
    overflow: hidden;
    gap: 10px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}



.image-wrapper {
    position: relative;
    height: 100%;
    /* Fill section */
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center horizontally/vertically */
    flex: 1;
    /* Both take equal width */
    overflow: hidden;
}

#source-img {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    display: block;
}

#white-bg-container {
    background-color: #ffffff;
    display: block;
    width: 0;
    /* JS will set these */
    height: 0;
}

#bbox-canvas-left,
#bbox-canvas-right {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Center canvas over image */
    pointer-events: none;
}

/* Bottom Section: Comparison (Remaining height) */
.comparison-section {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px;
    min-height: 0;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}

.option-card {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 2px solid transparent;
    overflow: hidden;
}

.option-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

.option-card.selected-left {
    border-color: var(--highlight-left);
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.4);
}

.option-card.selected-right {
    border-color: var(--highlight-right);
    box-shadow: 0 0 20px rgba(33, 150, 243, 0.4);
}

.card-image {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000;
    border-radius: 8px;
    margin-bottom: 5px;
}

.card-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.card-footer {
    padding-top: 5px;
    text-align: center;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.vs-divider {
    width: 2px;
    background: #444;
    height: 80%;
    opacity: 0.5;
}

/* Modal and Utilities same as before */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    width: 400px;
    max-width: 90%;
}

.close-modal {
    float: right;
    font-size: 1.5rem;
    cursor: pointer;
}

.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
}

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

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#loading-overlay.hidden {
    display: none;
}

/* Welcome Card */
.welcome-card {
    width: 600px;
    max-width: 95%;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 1px solid #333 !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.welcome-card h1 {
    margin: 0;
    color: var(--accent-color);
    text-align: center;
    font-size: 2rem;
}

.instructions-content {
    background: #252525;
    padding: 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.instructions-content ul {
    margin: 15px 0 0 0;
    padding-left: 20px;
}

.instructions-content li {
    margin-bottom: 10px;
}

.start-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.start-form label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#welcome-username {
    background: #2c2c2c;
    border: 1px solid #444;
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#welcome-username:focus {
    border-color: var(--accent-color);
}

.primary-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

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

.primary-btn:active {
    transform: scale(0.98);
}