:root {
    --bg-color: #0f0f13;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-color: #7c4dff;
    --accent-gradient: linear-gradient(135deg, #7c4dff 0%, #448aff 100%);
    --text-color: #f0f0f0;
    --text-secondary: #a0a0a0;
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
    --zoom-level: 2;
    --grid-base-size: 80px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0.5rem;
    max-width: 98vw;
    margin: 0 auto;
    overflow: hidden;
}

@media (max-width: 600px) {
    #app {
        height: auto;
        min-height: 100vh;
        overflow-y: visible;
    }
}

header {
    text-align: center;
    padding: 0.5rem 0;
}

h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

/* Progress Bar */
.progress-container {
    max-width: 300px;
    margin: 0 auto 0.2rem;
    padding: 0 0.5rem;
}

.progress-bar-wrapper {
    background: rgba(255, 255, 255, 0.05);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    box-shadow: 0 0 10px rgba(124, 77, 255, 0.3);
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    align-items: center;
}

.progress-stats {
    opacity: 0.6;
    font-size: 0.75rem;
}

#progress-percent {
    color: var(--accent-color);
    font-weight: 700;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: center;
    min-height: 0; /* Critical for inner scrolling */
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    gap: 2rem;
    min-height: 160px; /* Ensure enough height for large thumbs */
    background: linear-gradient(to bottom, rgba(15, 15, 19, 0.8) 0%, transparent 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.header-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.header-right {
    width: 200px;
    display: flex;
    justify-content: flex-end;
}

@media (max-width: 1200px) {
    .main-header {
        flex-direction: column;
        gap: 1.5rem;
        padding: 1rem;
    }
    .header-right {
        width: 100%;
        justify-content: center;
    }
}

.zoom-controls {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    width: 200px;
}

#zoom-slider {
    width: 100%;
    accent-color: var(--accent-color);
    cursor: pointer;
}

#zoom-value {
    color: var(--accent-color);
    font-weight: 700;
}

/* Mini Leaderboard */
.mini-leaderboard-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    animation: fadeIn 0.5s ease-out;
    min-width: 450px;
}

.mini-leaderboard-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-color);
    font-weight: 900;
    margin-left: 5px;
}

.mini-leaderboard-items {
    display: flex;
    gap: 1.25rem;
    align-items: flex-end;
}

.mini-item {
    position: relative;
    width: 90px; /* Much larger */
    height: 90px;
    border-radius: 50%;
    border: 4px solid var(--glass-border);
    background: var(--bg-color);
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

.mini-item:hover {
    transform: scale(1.1) translateY(-10px);
    border-color: var(--accent-color);
    z-index: 10;
    box-shadow: 0 15px 35px rgba(124, 77, 255, 0.6);
}

.mini-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mini-rank {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--accent-gradient);
    color: white;
    font-size: 0.8rem;
    font-weight: 900;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--bg-color);
    box-shadow: 0 3px 8px rgba(0,0,0,0.5);
}

.mini-item.first { 
    border-color: #ffd700; 
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.3); 
    width: 120px; height: 120px; /* Match height requested */
}
.mini-item.first .mini-rank { 
    background: linear-gradient(135deg, #ffd700, #ff8c00); 
    color: #000;
    width: 34px; height: 34px;
    font-size: 1rem;
}

.mini-item.second { 
    border-color: #c0c0c0; 
    width: 100px; height: 100px;
}
.mini-item.third { 
    border-color: #cd7f32; 
    width: 90px; height: 90px;
}

/* Comparison View */
.comparison-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
    flex: 1;
    overflow: hidden;
}

@media (max-width: 600px) {
    .comparison-container {
        grid-template-columns: 1fr;
        overflow: visible;
        flex: none;
    }
    
    .person-card {
        height: auto;
    }
    
    .image-container {
        aspect-ratio: auto;
    }
    
    .image-container img {
        width: 100%;
        height: auto;
        max-height: none;
        object-fit: contain;
    }
}

.person-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    height: 100%;
    min-height: 0;
}

.person-card:hover {
    transform: translateY(-5px) scale(1.02);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-color);
}

.person-card:active {
    transform: scale(0.98);
}

.image-container {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 16px;
    overflow: hidden;
    background: #1a1a20;
    position: relative;
}

.image-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: opacity 0.3s ease;
}

.person-name {
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
}

/* Desktop Grid for images */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(calc(var(--grid-base-size) * var(--zoom-level)), 1fr));
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.5rem;
    overflow-y: auto;
    flex: 1; /* Take remaining space in card */
    min-height: 0;
    padding-right: 5px;
}

.image-grid::-webkit-scrollbar {
    width: 4px;
}

.image-grid::-webkit-scrollbar-track {
    background: transparent;
}

.image-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.image-grid img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    transition: opacity 1s ease-in-out;
}

.image-grid-item {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
}

.image-grid img.fading {
    opacity: 0;
}

.desktop-mode .image-container {
    display: none; /* Hide the single image cycler on desktop */
}

.desktop-mode .image-grid {
    display: grid;
}

.mobile-mode .image-grid {
    display: none;
}

/* Leaderboard */
.leaderboard-container {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    padding: 2rem;
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: 85vh;
    overflow: hidden;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
}

.leaderboard-header h2 {
    font-size: 1.75rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.leaderboard-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
}

.search-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.6rem 1rem;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    width: 200px;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.08);
    width: 250px;
}

.sort-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 4px;
    border: 1px solid var(--glass-border);
}

.sort-btn {
    padding: 0.5rem 1rem;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sort-btn.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.4);
}

/* Podium Section */
.podium-section {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 1rem;
    padding: 2rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.podium-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    transition: transform 0.3s ease;
}

.podium-item:hover {
    transform: translateY(-10px);
}

.podium-item.first { order: 2; z-index: 3; }
.podium-item.second { order: 1; z-index: 2; }
.podium-item.third { order: 3; z-index: 1; }

.podium-image-wrapper {
    position: relative;
    border-radius: 50%;
    padding: 4px;
    background: var(--accent-gradient);
    box-shadow: 0 0 20px rgba(124, 77, 255, 0.4);
}

.podium-item.first .podium-image-wrapper { 
    width: 140px; height: 140px; 
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}
.podium-item.second .podium-image-wrapper { 
    width: 110px; height: 110px; 
    background: linear-gradient(135deg, #c0c0c0 0%, #708090 100%);
    box-shadow: 0 0 20px rgba(192, 192, 192, 0.2);
}
.podium-item.third .podium-image-wrapper { 
    width: 100px; height: 100px; 
    background: linear-gradient(135deg, #cd7f32 0%, #8b4513 100%);
    box-shadow: 0 0 15px rgba(205, 127, 50, 0.2);
}

.podium-thumb {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg-color);
}

.podium-rank {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: white;
    border: 2px solid var(--bg-color);
}

.podium-item.first .podium-rank { background: #ffd700; color: #000; }
.podium-item.second .podium-rank { background: #c0c0c0; color: #000; }
.podium-item.third .podium-rank { background: #cd7f32; color: #fff; }

.podium-name {
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.podium-stats {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Leaderboard List */
.leaderboard-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--glass-border);
    transform: scale(1.01);
}

.rank-number {
    font-weight: 800;
    font-size: 1rem;
    color: var(--text-secondary);
    width: 2.5rem;
}

.leaderboard-thumb {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    object-fit: cover;
    margin-right: 1.25rem;
    background: #1a1a20;
    border: 1px solid var(--glass-border);
}

.person-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.person-name {
    font-weight: 700;
    font-size: 1rem;
}

.person-stats-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.win-rate-container {
    width: 100px;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.win-rate-bar {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 2px;
}

.wins-count {
    font-weight: 700;
    color: var(--text-color);
    text-align: right;
}

.win-percent-badge {
    background: rgba(124, 77, 255, 0.1);
    color: var(--accent-color);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 800;
}

/* Reset Buttons on Leaderboard */
.podium-reset-btn, .list-reset-btn {
    background: rgba(255, 50, 50, 0.1);
    border: 1px solid rgba(255, 50, 50, 0.2);
    color: #ff5252;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

.podium-item:hover .podium-reset-btn,
.leaderboard-item:hover .list-reset-btn {
    opacity: 1;
    pointer-events: auto;
}

.podium-reset-btn:hover, .list-reset-btn:hover {
    background: rgba(255, 50, 50, 0.2);
    border-color: #ff5252;
    transform: scale(1.1);
}

.podium-reset-btn {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(30%, -30%);
}

.list-reset-btn {
    margin-left: 1rem;
}

/* Detail Overlay */
.detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    backdrop-filter: blur(10px);
}

.detail-content {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

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

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    overflow-y: auto;
    padding-bottom: 1rem;
}

.detail-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

/* Navigation / Actions */
.nav-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
    padding-bottom: 0.5rem;
}

button.primary {
    background: var(--accent-gradient);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.3);
}

button.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(124, 77, 255, 0.4);
}

button.secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

button.secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

button.danger {
    background: rgba(255, 50, 50, 0.1);
    border: 1px solid rgba(255, 50, 50, 0.3);
    color: #ff5252;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

button.danger:hover {
    background: rgba(255, 50, 50, 0.2);
    border-color: #ff5252;
}

/* Transitions */
.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Loader */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--card-bg);
    border-bottom-color: var(--accent-color);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin: 2rem auto;
}

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

.hidden {
    display: none !important;
}

/* Image Controls */
.img-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    z-index: 2;
}

.img-prev { left: 5px; }
.img-next { right: 5px; }

.nav-actions {
    position: relative;
    z-index: 100;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.modal-content {
    background: #1a1a20;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #ff5252;
}

.modal-content p {
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}
