/* Leaderboard Styles */

.leaderboard-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    /* Above pause overlay (10001) so leaderboard and its close button are clickable when paused */
    z-index: 10002;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
    /* Ensure pointer events work correctly */
    pointer-events: auto;
}

.leaderboard-modal.show {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.leaderboard-content {
    background: #ffffff;
    border-radius: 8px;
    width: 98vw;
    max-width: none;
    height: 96vh;
    max-height: none;
    overflow-y: auto;
    box-shadow: 0 8px 28px rgba(44, 62, 80, 0.22);
    animation: slideUp 0.3s ease;
    pointer-events: auto;
    position: relative;
    display: flex;
    flex-direction: column;
    font-family: 'Noto Sans', sans-serif;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: #2c3e50;
    border-bottom: 3px solid #3498db;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
}

.leaderboard-title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
}

.leaderboard-title h2 {
    margin: 0;
    color: #ffffff;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.trophy-icon {
    display: flex;
    align-items: center;
    line-height: 0;
    color: #ffffff;
}

.trophy-icon svg {
    display: block;
}

.leaderboard-close {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 32px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    pointer-events: auto;
    touch-action: manipulation;
}

.leaderboard-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.leaderboard-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 16px 24px;
    background: #f4f6f8;
    border-bottom: 1px solid #e5e7eb;
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 12px;
    font-weight: bold;
    color: #333;
    font-family: 'Oswald', sans-serif;
}

.filter-select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Noto Sans', sans-serif;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 150px;
}

.filter-select:hover {
    border-color: #3498db;
}

.filter-select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.lb-anonymize-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.lb-anonymize-ico {
    display: inline-flex;
    color: #334155;
    line-height: 0;
}

.lb-anonymize-ico svg {
    display: block;
}

.leaderboard-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #3498db;
    color: #ffffff;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 600;
    font-family: 'Noto Sans', sans-serif;
    cursor: pointer;
    align-self: flex-end;
    margin-top: 18px;
}

.leaderboard-refresh-btn:hover {
    background: #2980b9;
}

.lb-refresh-ico {
    display: inline-flex;
    line-height: 0;
}

.lb-refresh-ico svg {
    display: block;
}

.leaderboard-body {
    padding: 24px;
    background: #ffffff;
    border-radius: 0 0 8px 8px;
}

#leaderboard-chart-container {
    margin-bottom: 30px;
    height: 380px;
    position: relative;
    pointer-events: auto;
    overflow-x: auto;
    overflow-y: hidden;
}

#leaderboard-chart-wrapper {
    height: 100%;
    min-height: 380px;
    position: relative;
    pointer-events: auto;
}

#leaderboard-chart {
    /* Ensure Chart.js canvas can receive pointer events for interactions */
    pointer-events: auto;
    cursor: pointer;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 72px 1fr auto;
    grid-template-rows: auto;
    gap: 10px;
    padding: 15px 20px;
    background: #f4f6f8;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.leaderboard-item:hover {
    background: #eef2f6;
}

.leaderboard-item.top-1 {
    background: #fff6d8;
    border-left-color: #d4a017;
}

.leaderboard-item.top-2 {
    background: #f3f4f6;
    border-left-color: #8a8a8a;
}

.leaderboard-item.top-3 {
    background: #f6e6d4;
    border-left-color: #a86b32;
}

.leaderboard-rank {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Oswald', sans-serif;
    white-space: nowrap;
}

.leaderboard-name {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    font-family: 'Oswald', sans-serif;
}

.leaderboard-metric {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
}

.metric-label {
    color: #666;
    font-size: 14px;
}

.metric-value {
    font-weight: bold;
    color: #3498db;
    font-size: 18px;
}

.leaderboard-loading,
.leaderboard-error {
    text-align: center;
    padding: 40px;
    font-size: 18px;
    color: #666;
}

.leaderboard-empty {
    text-align: center;
    padding: 60px 40px;
    font-size: 20px;
    color: #888;
    font-style: italic;
    background: #f4f6f8;
    border-radius: 12px;
}

/* Responsive design */
@media (max-width: 768px) {
    .leaderboard-content {
        width: 98vw;
        height: 96vh;
        max-width: none;
        max-height: none;
    }
    
    .leaderboard-filters {
        flex-direction: column;
    }
    
    .filter-select {
        min-width: 100%;
    }
    
    .leaderboard-item {
        grid-template-columns: 64px 1fr;
    }
    
    .leaderboard-metric {
        grid-column: 1 / 3;
    }
}

/* ========== Question leaderboard (top 5 per question) ========== */
.question-leaderboard-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10003;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    animation: fadeIn 0.25s ease;
}

.question-leaderboard-content {
    background: #ffffff;
    border-radius: 8px;
    width: 92vw;
    max-width: 560px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(44, 62, 80, 0.22);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    font-family: 'Noto Sans', sans-serif;
}

.question-leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: #2c3e50;
    border-bottom: 3px solid #3498db;
}

.question-leaderboard-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.question-leaderboard-title h2 {
    margin: 0;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
}

.question-leaderboard-close {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 32px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.question-leaderboard-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.question-leaderboard-filters {
    padding: 12px 20px;
    background: #f4f6f8;
    border-bottom: 1px solid #e5e7eb;
}

.question-leaderboard-filters .filter-group label {
    color: #333333;
    font-size: 0.75rem;
}

.question-leaderboard-accuracy-note {
    color: #666666;
    font-size: 0.7rem;
    margin-top: 4px;
    display: block;
}

.question-leaderboard-filters .filter-select {
    min-width: 140px;
    background: rgba(255, 255, 255, 0.95);
}

.question-leaderboard-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.question-leaderboard-loading,
.question-leaderboard-error,
.question-leaderboard-empty {
    text-align: center;
    padding: 24px;
    color: #666666;
}

.question-leaderboard-podium {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

/* Slots stretch to full wrapper height so block height % uses full rectangle */
.question-podium-wrapper {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 8px;
    padding: 10px 0 8px;
    min-height: 220px;
}

.question-podium-slot {
    flex: 1;
    max-width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.question-podium-block {
    width: 100%;
    min-height: 48px;
    border-radius: 10px 10px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 4px 10px;
    box-sizing: border-box;
}

.question-podium-rank-1 .question-podium-block {
    background: #e6b800;
    color: #5c4a00;
}

.question-podium-rank-2 .question-podium-block {
    background: #c5c5c5;
    color: #333333;
}

.question-podium-rank-3 .question-podium-block {
    background: #c4843a;
    color: #ffffff;
}

.question-podium-rank-4 .question-podium-block,
.question-podium-rank-5 .question-podium-block {
    background: #5c6b7a;
    color: #ffffff;
}

.question-podium-empty {
    background: #eef1f4 !important;
    color: #888888 !important;
}

.question-podium-medal {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.question-podium-name {
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
    margin-bottom: 2px;
}

.question-podium-value {
    font-size: 0.9rem;
    font-weight: 700;
}

.question-podium-placeholder {
    font-size: 0.85rem;
    opacity: 0.7;
}

.question-leaderboard-metric-legend {
    text-align: center;
    font-size: 0.75rem;
    color: #666666;
    margin-top: 10px;
}

/* Your rank (below podium) — when student didn't make top 5 or has no attempt yet */
.question-leaderboard-your-rank {
    text-align: center;
    margin-top: 16px;
    padding: 12px 16px;
    background: #f4f6f8;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.question-leaderboard-your-rank-message {
    font-size: 0.95rem;
    font-weight: 600;
    color: #333333;
    margin: 0 0 4px 0;
}
.question-leaderboard-your-rank-detail {
    font-size: 0.8rem;
    color: #666666;
    margin: 0;
}
