/* =========================================================
   typescore.css — TypeScore™ Card, Breakdown Modal & Public Profile
   ========================================================= */

/* ── TypeScore Card (Dashboard) ────────────────────────────────────────── */
.typescore-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--bg-secondary, #f5f5f5) 0%, var(--bg-tertiary, #e8e8e8) 100%);
    border: 1px solid var(--border-color, #ccc);
    border-radius: 14px;
    padding: 14px 18px;
    margin: 0 0 14px;
    gap: 12px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.typescore-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #f59e0b, #8b5cf6, #3b82f6, #10b981);
    opacity: 0.85;
}

.typescore-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

/* Left: score number + label */
.ts-card-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
    z-index: 1;
}

.ts-score-wrap {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.ts-score-num {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary, #000);
    line-height: 1;
    letter-spacing: -1px;
}

.ts-score-suffix {
    font-size: 0.78rem;
    color: var(--text-tertiary, #999);
    font-weight: 500;
}

.ts-label {
    font-size: 0.72rem;
    color: var(--text-tertiary, #999);
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ts-placement {
    font-size: 0.68rem;
    color: #f59e0b;
    font-weight: 600;
    margin-top: 2px;
}

/* Right: tier + trend + button */
.ts-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    position: relative;
    z-index: 1;
}

.ts-tier {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.ts-trend {
    display: none;
    /* Hidden now that chart is background */
}

#typeScoreSparkline {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 0;
    pointer-events: none;
    opacity: 0.35;
}

.ts-breakdown-btn {
    background: var(--accent-solid, var(--accent-color, #1976d2));
    color: var(--accent-contrast-text, #fff);
    border: none;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    white-space: nowrap;
}

.ts-breakdown-btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

/* -- TypeScore Low-end performance mode ---------------------------------- */
html.performance-mode .typescore-card,
html.performance-mode .ts-modal-overlay,
html.performance-mode .ts-modal-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

html.performance-mode .typescore-card,
html.performance-mode .ts-breakdown-btn,
html.performance-mode .ts-bar-fill,
html.performance-mode .ts-modal-overlay,
html.performance-mode .ts-modal-card {
    transition: none !important;
    animation: none !important;
}

html.performance-mode .typescore-card:hover,
html.performance-mode .ts-breakdown-btn:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* ── Breakdown Modal ──────────────────────────────────────────────────── */
.ts-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: ts-modal-in 0.2s ease;
}

@keyframes ts-modal-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.ts-modal-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #ccc);
    border-radius: 20px;
    padding: 28px 24px 22px;
    width: min(92%, 480px);
    position: relative;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
    animation: ts-card-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ts-card-up {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.ts-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-tertiary, #999);
    cursor: pointer;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    padding: 0;
    z-index: 10;
}

.ts-modal-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary, #000);
}

[data-theme="dark"] .ts-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.ts-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary, #000);
    margin: 0 0 16px;
}

.ts-modal-footer {
    font-size: 0.72rem;
    color: var(--text-tertiary, #999);
    margin: 14px 0 0;
    line-height: 1.5;
}

/* ── Breakdown panel (rendered by TypeScoreManager.renderBreakdown) ─── */
.ts-breakdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-light, #eee);
}

.ts-header-left {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ts-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    text-align: right;
}

.ts-total-display {
    font-size: 3.2rem;
    font-weight: 950;
    line-height: 0.85;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.ts-total-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.ts-total-delta {
    font-size: 1.1rem;
    font-weight: 700;
    padding-bottom: 4px;
}

.ts-tier-badge {
    border: 1.2px solid currentColor;
    border-radius: 20px;
    padding: 1.5px 7px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.6px;
    width: fit-content;
    text-transform: uppercase;
}

.ts-percentile-card {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
}

.ts-percentile-num {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1;
}

.ts-percentile-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-top: -2px;
}

/* Delta Colors */
.ts-total-delta.positive,
.ts-delta.positive {
    color: #10b981;
    font-weight: 800;
}

.ts-total-delta.negative,
.ts-delta.negative {
    color: #ef4444;
    font-weight: 800;
}

.ts-total-delta.neutral,
.ts-delta.neutral {
    color: var(--text-tertiary);
}

/* ── Component Rows ──────────────────────────────────────────────────── */
.ts-breakdown-rows {
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.ts-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 10px;
}

.ts-row-label {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.ts-row-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary, #000);
}

.ts-row-desc {
    font-size: 0.68rem;
    color: var(--text-tertiary, #999);
}

.ts-row-bar-wrap {
    width: 90px;
}

.ts-bar-track {
    height: 6px;
    background: var(--bg-tertiary, #eee);
    border-radius: 99px;
    overflow: hidden;
}

.ts-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.ts-row-val {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary, #000);
    min-width: 44px;
    text-align: right;
}

.ts-row-max {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-tertiary, #999);
}

/* ── Placement Note ──────────────────────────────────────────────────── */
.ts-placement-note {
    margin-top: 16px;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(245, 158, 11, 0.04));
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    font-size: 0.78rem;
    color: #f59e0b;
    font-weight: 600;
    text-align: center;
}

/* ── Public Profile TypeScore Stat ───────────────────────────────────── */
.ts-public-stat .ts-public-score {
    font-weight: 800;
    font-size: 1.4rem;
}

.ts-public-stat #publicTypeScoreLabel {
    font-size: 0.7rem;
    letter-spacing: 0.2px;
}

/* ── Public Profile Header TypeScore (Compact Badge) ────────────────── */
/* ── Public Profile Header TypeScore (Compact Badge) ────────────────── */
.public-typescore-header-row {
    position: absolute;
    top: 40px;
    right: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    border: 1px solid var(--border-light, #eee);
    z-index: 5;
    line-height: 1;
    transition: all 0.3s ease;
}

.public-typescore-header-row:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.ts-header-label {
    font-size: 0.52rem;
    font-weight: 700;
    color: var(--text-tertiary, #999);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 0.8;
}

.ts-header-value {
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--text-primary, #000);
}

.ts-header-tier {
    font-size: 0.58rem;
    font-weight: 800;
    margin-top: 2px;
    opacity: 0;
    /* Hidden by default */
    transform: translateY(-5px);
    transition: all 0.2s ease;
    max-height: 0;
    overflow: hidden;
}

.public-typescore-header-row:hover .ts-header-tier {
    opacity: 1;
    transform: translateY(0);
    max-height: 20px;
    margin-top: 3px;
}

/* Flag Badge Integration & Positioning (Non-Clipping) */
#publicProfileModal .public-profile-card,
#publicProfileCard,
.public-profile-header-row {
    overflow: visible !important;
    /* Total protection against clipping */
}

.public-avatar-container {
    position: relative !important;
    width: 72px !important;
    height: 72px !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
}

.public-avatar-flag-badge {
    position: absolute !important;
    bottom: 8px !important;
    /* Pull well inward to avoid modal edges */
    right: 8px !important;
    /* Pull well inward to avoid modal edges */
    transform: translate(15%, 15%) !important;
    /* Subtle overlap on corner */
    width: 25px !important;
    height: 25px !important;
    background: var(--bg-secondary) !important;
    border: 2.5px solid var(--bg-primary) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.95rem !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6) !important;
    z-index: 99 !important;
    /* Top priority */
    overflow: hidden !important;
    line-height: 0 !important;
    padding: 0 !important;
}

.public-avatar-flag-badge .country-flag-img {
    width: 100% !important;
    height: 100% !important;
    margin-right: 0 !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: block !important;
    box-shadow: none !important;
}

.public-profile-name {
    max-width: 78% !important;
    /* Extra safety for TypeScore badge */
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    font-size: 1.25rem !important;
    font-weight: 800 !important;
    margin: 0 0 2px 0 !important;
    line-height: 1.2 !important;
}

.public-profile-handle {
    opacity: 0.7 !important;
    font-size: 0.85rem !important;
    margin-bottom: 2px !important;
    display: block !important;
}

/* Close button cornering and hover */
.public-profile-card .close-public-profile-btn {
    top: 8px !important;
    right: 8px !important;
    font-size: 24px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.public-profile-card .close-public-profile-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: var(--text-primary) !important;
}

/* Guard against overlapping with the TypeScore badge */
.ts-padded-info {
    padding-right: 80px !important;
}

/* Fix for "touching border" issue on public profile modal */
.public-profile-body {
    padding-left: 20px !important;
    padding-right: 20px !important;
}

[data-theme="dark"] .public-typescore-header-row {
    background: rgba(255, 255, 255, 0.02);
    border-color: #3d4455;
}

[data-theme="dark"] .public-typescore-header-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Desktop-specific adjustments for vertical alignment */
@media screen and (min-width: 481px) {
    .public-typescore-header-row {
        top: 45px;
        /* Moved downward on desktop */
        right: 18px;
    }
}

/* ── Profile Modal TypeScore Row ─────────────────────────────────────── */
.profile-typescore-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    margin: 8px 0 4px;
    background: var(--bg-tertiary, #eee);
    border-radius: 10px;
    gap: 8px;
}

.profile-ts-score {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary, #000);
}

.profile-ts-tier {
    font-size: 0.78rem;
    font-weight: 700;
}

.profile-ts-label {
    font-size: 0.72rem;
    color: var(--text-tertiary, #999);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.4px;
}

.profile-ts-trend {
    font-size: 1rem;
}

/* ── Dark Mode Adjustments ───────────────────────────────────────────── */
[data-theme="dark"] .typescore-card {
    background: linear-gradient(135deg, #252d3d 0%, #1e2635 100%);
}

[data-theme="dark"] .ts-modal-card {
    background: #1a1f2e;
    border-color: #3d4455;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .ts-bar-track {
    background: #2d3748;
}

[data-theme="dark"] .ts-breakdown-header {
    border-bottom-color: #3d4455;
}

[data-theme="dark"] .ts-placement-note {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.06));
}

[data-theme="dark"] .profile-typescore-row {
    background: #252d3d;
}

/* Minimal dark readability tuning */
[data-shop-theme="minimal"] .typescore-card {
    border-color: #3a3a3a !important;
    background: linear-gradient(135deg, #101010 0%, #080808 100%) !important;
}

[data-shop-theme="minimal"] .ts-label,
[data-shop-theme="minimal"] .ts-score-suffix {
    color: #d7d7d7 !important;
    opacity: 1 !important;
}

[data-shop-theme="minimal"] .ts-score-suffix {
    font-weight: 700;
}

[data-shop-theme="minimal"] #typeScoreSparkline {
    opacity: 0.28;
}

/* -- Mobile ------------------------------------------------------------ */
@media (max-width: 480px) {
    .ts-score-num {
        font-size: 1.6rem;
    }

    .ts-modal-card {
        padding: 22px 16px 18px;
    }

    .ts-row {
        grid-template-columns: 1fr auto auto auto;
        gap: 6px;
    }

    .ts-row-bar-wrap {
        width: 60px;
    }
}

/* -- TypeScore Delta & Enhanced Trends --------------------------------- */
.ts-delta {
    font-size: 0.65rem;
    font-weight: 700;
    margin-right: 6px;
    padding: 2px 5px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    background: var(--bg-tertiary, #eee);
    color: var(--text-tertiary, #999);
}

.ts-delta.positive {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
}

.ts-delta.negative {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

[data-theme="dark"] .ts-delta.positive {
    background: rgba(16, 185, 129, 0.2);
}

[data-theme="dark"] .ts-delta.negative {
    background: rgba(239, 68, 68, 0.2);
}

.ts-trend-improving {
    color: #10b981;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.ts-trend-stable {
    color: var(--text-tertiary, #999);
}

.ts-trend-declining {
    color: #ef4444;
}

@media (prefers-reduced-motion: reduce) {

    .typescore-card,
    .ts-breakdown-btn,
    .ts-bar-fill,
    .ts-modal-overlay,
    .ts-modal-card {
        transition: none !important;
        animation: none !important;
    }

    .typescore-card:hover,
    .ts-breakdown-btn:hover {
        transform: none !important;
    }
}
