/* ============================================================================
   Leaderboard template — faithful replica of the in-app TripRank leaderboard.
   Rendered live as DOM (not canvas) and exported with html2canvas, so the
   preview is exactly what downloads (WYSIWYG). Avatars + flags + medals are
   real images, which is why this is HTML rather than the PIL pipeline the
   other templates use.
   ============================================================================ */

/* ---- Preview card (the thing that gets captured) ------------------------- */
.leaderboard-preview {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* No global `.hidden` rule exists — each preview hides itself (see route-map /
   phone-nav). Without this the teal download button leaks onto every screen. */
.leaderboard-preview.hidden {
    display: none;
}

.lb-capture {
    width: 460px;
    max-width: 100%;
    /* Subtle top-lit vignette over near-black, matching the app screen. */
    background: radial-gradient(130% 80% at 50% 0%, #14161e 0%, #0a0a0f 58%);
    border-radius: 28px;
    padding: 34px 22px 28px;
    box-sizing: border-box;
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.lb-logo {
    display: block;
    width: 62%;
    max-width: 280px;
    margin: 0 auto 14px;
}

.lb-title {
    text-align: center;
    color: #ffffff;
    font-weight: 700;
    font-size: 38px;
    letter-spacing: -0.5px;
    margin: 6px 0 10px;
}

.lb-subtitle {
    text-align: center;
    color: #8b909c;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 22px;
}

/* ---- Rows ---------------------------------------------------------------- */
.lb-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Faint medal-coloured tint for the podium (overridden by .is-you). */
.lb-row.rank-1 { background: rgba(245, 197, 24, 0.06); border-color: rgba(245, 197, 24, 0.14); }
.lb-row.rank-2 { background: rgba(255, 255, 255, 0.05); }
.lb-row.rank-3 { background: rgba(224, 144, 75, 0.07); border-color: rgba(224, 144, 75, 0.14); }

.lb-row.is-you {
    background: rgba(77, 184, 184, 0.08);
    border: 1.5px solid #4DB8B8;
}

/* Medal / rank number slot — fixed width so avatars line up. */
.lb-medal {
    width: 30px;
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lb-medal img {
    width: 26px;
    height: auto;
    display: block;
}
.lb-rank-num {
    color: #6b7280;
    font-weight: 700;
    font-size: 15px;
}

/* Avatar */
.lb-avatar {
    width: 52px;
    height: 52px;
    min-width: 52px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, #2a2d3a, #3a4150);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.lb-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Name + meta */
.lb-info {
    flex: 1;
    min-width: 0;
}
.lb-name {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    font-weight: 700;
    font-size: 18px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lb-you-badge {
    flex: none;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #4DB8B8;
    background: rgba(77, 184, 184, 0.16);
    border: 1px solid rgba(77, 184, 184, 0.5);
    border-radius: 6px;
    padding: 2px 6px;
    line-height: 1;
}
.lb-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: #8b909c;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lb-flag {
    width: 18px;
    height: 13px;
    border-radius: 2px;
    object-fit: cover;
    flex: none;
    background: #d8dbe2; /* fallback / "Unknown" white-ish flag */
}
.lb-meta-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Value */
.lb-value-wrap {
    text-align: right;
    flex: none;
}
.lb-value {
    font-weight: 800;
    font-size: 28px;
    line-height: 1;
    color: #ffffff;
}
.lb-row.rank-1 .lb-value { color: #F5C518; }
.lb-row.rank-2 .lb-value { color: #C8CCD4; }
.lb-row.rank-3 .lb-value { color: #E0905A; }
.lb-unit {
    color: #8b909c;
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

/* ---- Left-panel editor --------------------------------------------------- */
.lb-row-editor {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 12px;
}
.lb-row-editor-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.lb-row-editor-rank {
    font-weight: 800;
    font-size: 14px;
    color: #4DB8B8;
    flex: 1;
}
.lb-mini-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cbd2e0;
    border-radius: 8px;
    width: 28px;
    height: 28px;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.lb-mini-btn:hover { background: rgba(255, 255, 255, 0.12); }
.lb-mini-btn.lb-remove:hover { background: rgba(239, 68, 68, 0.25); border-color: rgba(239, 68, 68, 0.5); }
.lb-mini-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.lb-editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.lb-editor-grid .lb-field-full { grid-column: 1 / -1; }
.lb-field label {
    display: block;
    font-size: 11px;
    color: #8b909c;
    margin-bottom: 3px;
    font-weight: 600;
}
.lb-field input,
.lb-field select {
    width: 100%;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
}
.lb-field input:focus,
.lb-field select:focus {
    outline: none;
    border-color: #4DB8B8;
}

.lb-avatar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.lb-avatar-thumb {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, #2a2d3a, #3a4150);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.lb-avatar-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lb-avatar-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    color: #cbd2e0;
    border-radius: 8px;
    padding: 8px;
    font-size: 12px;
    cursor: pointer;
    text-align: center;
}
.lb-avatar-btn:hover { background: rgba(255, 255, 255, 0.1); }

.lb-you-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #cbd2e0;
    cursor: pointer;
    user-select: none;
}
.lb-you-toggle input { width: auto; }

.lb-add-row {
    width: 100%;
    background: linear-gradient(135deg, #4DB8B8, #3a9a9a);
    border: none;
    color: #06121a;
    font-weight: 700;
    border-radius: 10px;
    padding: 11px;
    font-size: 14px;
    cursor: pointer;
}
.lb-add-row:hover { filter: brightness(1.08); }

.lb-download-btn {
    width: 460px;
    max-width: 100%;
    background: linear-gradient(135deg, #4DB8B8, #3a9a9a);
    border: none;
    color: #06121a;
    font-weight: 800;
    border-radius: 14px;
    padding: 15px;
    font-size: 16px;
    cursor: pointer;
}
.lb-download-btn:hover { filter: brightness(1.08); }
.lb-download-btn:disabled { opacity: 0.6; cursor: wait; }

/* Video export — onboarding-style "climb to #1" animation, recorded to a clip.
   Distinct purple→pink gradient so it reads as the motion sibling of the image. */
.lb-download-video-btn {
    margin-top: -8px; /* sit just under the image button (parent gap is 16px) */
    color: #fff;
    background: linear-gradient(135deg, #7c5cff, #c44dff);
}
