.profile-card {
    background: linear-gradient(150deg, #c62828 0%, #e53935 40%, #ef5350 80%, #e57373 100%);
    border-radius: 18px;
    padding: 24px 20px 20px;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(198, 40, 40, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Pokéball decorative circle */
.profile-card::before {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 160px;
    height: 160px;
    border: 18px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    pointer-events: none;
}

.profile-card::after {
    content: '';
    position: absolute;
    top: -40%;
    left: -20%;
    width: 60%;
    height: 80%;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 50%;
    pointer-events: none;
}

.profile-avatar {
    font-size: 3.5rem;
    margin-bottom: 4px;
    line-height: 1;
}

.profile-badge-avatar {
    width: 56px;
    height: 56px;
    image-rendering: pixelated;
    margin-bottom: 4px;
}

.badge-img {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.profile-name {
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 1px;
    font-family: var(--font-body, Arial);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.profile-title {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 2px;
}

.badge-progress-wrap {
    width: 100%;
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 16px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.badge-progress-label {
    font-size: 0.78rem;
    font-weight: bold;
    opacity: 0.95;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 5px;
    overflow: hidden;
}

.badge-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.95));
    border-radius: 5px;
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

.badge-progress-pct {
    font-size: 0.72rem;
    opacity: 0.8;
    text-align: right;
}

.profile-rank {
    display: inline-block;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    padding: 4px 14px;
    font-size: 0.85rem;
    margin-top: 6px;
    font-weight: bold;
}

.profile-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 8px 0;
}

.mode-stats-section {
    background: #f8f8f8;
    border-radius: var(--radius);
    padding: 12px;
    margin: 4px 0 8px;
    border: 2px solid #eee;
}

.mode-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mode-stat-item {
    background: white;
    border-radius: 10px;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 2px solid #eee;
}

.mode-stat-val {
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--red);
}

.mode-stat-lbl {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-align: center;
}

.stat-item {
    background: #f4f4f8;
    border-radius: var(--radius);
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 2px solid #e0e0e8;
    transition: transform var(--t), box-shadow var(--t);
    position: relative;
    overflow: hidden;
}

.stat-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.stat-val {
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--red);
    font-family: var(--font-pixel, monospace);
}

.stat-lbl {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.3;
    font-family: var(--font-body, Arial);
    font-weight: 700;
}

.worst-pokemon-card {
    background: #fff8e1;
    border: 2px solid var(--gold);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 4px 0;
}

.worst-pokemon-title {
    font-size: 0.78rem;
    font-weight: 900;
    color: #7a6000;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.worst-pokemon-body {
    display: flex;
    align-items: center;
    gap: 14px;
}

.worst-pokemon-img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 10px;
    background: white;
    border: 2px solid var(--gold);
    padding: 4px;
    flex-shrink: 0;
}

.worst-pokemon-name {
    font-size: 1rem;
    font-weight: 900;
    color: #333;
    word-break: break-word;
}

.worst-pokemon-count {
    font-size: 0.78rem;
    color: var(--red-dark);
    font-weight: bold;
    margin-top: 2px;
}

.badges-section {
    text-align: left;
    margin-top: 2px;
}

.badges-section>p {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.badges-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 6px;
}

.badge-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: bold;
    border: 2px solid;
    transition: transform var(--t), box-shadow var(--t);
    min-width: 0;
    overflow: hidden;
}

.badge-item>div {
    min-width: 0;
    overflow: hidden;
}

.badge-item>div>div:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-item.unlocked {
    background: #fffde7;
    border-color: var(--gold);
    color: #7a6000;
}

.badge-item.unlocked:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(240, 192, 64, 0.3);
}

.badge-item.locked {
    background: #f5f5f5;
    border-color: #ddd;
    color: #bbb;
    filter: grayscale(1);
    opacity: 0.7;
}

.badge-level-req {
    font-size: 0.72rem;
    color: #888;
    margin-top: 2px;
}

@media (max-width: 850px) {
    .profile-stats {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .badges-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-item {
        padding: 10px 6px;
    }

    .badge-item {
        padding: 8px 10px;
        font-size: 0.78rem;
        gap: 6px;
    }

    .worst-pokemon-img {
        width: 48px;
        height: 48px;
    }

    .profile-name {
        font-size: 1.3rem;
    }

    .profile-avatar {
        font-size: 3rem;
    }
}

@media (max-width: 380px) {
    .profile-stats {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .stat-val {
        font-size: 1rem;
    }

    .stat-lbl {
        font-size: 0.62rem;
    }

    .profile-name {
        font-size: 1.1rem;
    }

    .profile-avatar {
        font-size: 2.6rem;
    }

    .badge-item {
        font-size: 0.72rem;
        padding: 7px 8px;
    }

    .worst-pokemon-img {
        width: 42px;
        height: 42px;
    }
}

.history-section {
    margin-top: 20px;
    background: white;
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f8f8f8;
    border-radius: 10px;
    font-size: 0.85rem;
}

.history-rank {
    font-weight: bold;
    color: #999;
    min-width: 24px;
}

.history-mode {
    font-size: 1rem;
}

.history-score {
    font-weight: bold;
    color: #1a3a9e;
    min-width: 60px;
}

.history-pokemon {
    flex: 1;
    color: #555;
    font-size: 0.8rem;
}

.history-date {
    color: #aaa;
    font-size: 0.75rem;
    white-space: nowrap;
}

.pokedex-filter-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 0 2px;
}

.filter-btn {
    padding: 6px 12px;
    border-radius: 20px;
    border: 2px solid var(--border, #ddd);
    background: white;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn.active {
    background: var(--primary, #1a3a9e);
    color: white;
    border-color: var(--primary, #1a3a9e);
}

.pokedex-grid-flat {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 4px 0;
}

.fav-btn {
    position: absolute;
    top: 3px;
    left: 3px;
    bottom: unset;
    right: unset;
    background: none;
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0.4;
    padding: 0;
    margin: 0;
    line-height: 1;
    min-width: unset;
    box-shadow: none;
    width: auto;
    height: auto;
    border-radius: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.fav-btn.fav-active {
    opacity: 1;
}

.fav-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}

.pokedex-item {
    position: relative;
}

.global-stat {
    position: absolute;
    bottom: 2px;
    left: 2px;
    font-size: 0.6rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border-radius: 6px;
    padding: 1px 4px;
    pointer-events: none;
    line-height: 1.4;
    white-space: nowrap;
}

/* ── XP bar (Pokémon HP bar style) ──────────────── */
.xp-bar-section {
    width: 100%;
    margin: 10px 0 2px;
}

.xp-bar-label {
    font-family: var(--font-body, Arial);
    font-size: 0.75rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.95);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* HP bar look: dark outer container */
.xp-bar-wrap {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 5px;
    height: 14px;
    overflow: hidden;
    border: 2px solid rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.4);
    padding: 2px;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #f0c040, #ffd700);
    border-radius: 3px;
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 0 6px rgba(240, 192, 64, 0.6);
}

.xp-bar-sub {
    font-family: var(--font-body, Arial);
    font-size: 0.66rem;
    color: rgba(255, 255, 255, 0.75);
    margin-top: 3px;
    text-align: right;
    font-weight: 700;
}

/* ── Pokédex popup ───────────────────────────────── */
.pokedex-popup-box {
    max-width: 380px;
    width: 94vw;
    padding: 16px 22px 22px;
    position: relative;
    gap: 0;
}

.popup-close-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.pokedex-popup-header {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.popup-img {
    width: 96px;
    height: 96px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.popup-name {
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--red);
    margin-bottom: 2px;
}

.popup-id {
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 6px;
}

.popup-types {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.popup-type {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.popup-desc {
    font-size: 0.82rem;
    color: #555;
    font-style: italic;
    margin: 0 0 14px;
    line-height: 1.5;
    border-top: 1px solid #f0f0f0;
    padding-top: 10px;
}

.popup-stats {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.popup-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
}

.popup-stat-name {
    width: 56px;
    font-weight: bold;
    color: #555;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.popup-stat-bar-wrap {
    flex: 1;
    height: 9px;
    background: #f0f0f0;
    border-radius: 5px;
    overflow: hidden;
}

.popup-stat-bar {
    height: 100%;
    background: var(--red);
    border-radius: 5px;
    transition: width 0.5s ease;
}

.popup-stat-val {
    width: 30px;
    text-align: right;
    font-weight: bold;
    color: var(--red);
    font-size: 0.78rem;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #aaa;
    padding: 0 4px;
    line-height: 1;
    min-width: unset;
    box-shadow: none;
    border-radius: 0;
    font-weight: bold;
    transition: color 0.15s;
}

.modal-close-btn:hover {
    color: var(--red);
    background: none;
    border: none;
    box-shadow: none;
}

/* ── Share canvas btn ────────────────────────────── */
.share-canvas-btn {
    background: #1877f2;
    border-color: #125ab8;
    box-shadow: 0 4px 0 #125ab8;
    color: white;
}

/* ── Public profile banner ───────────────────────── */
.public-profile-banner {
    background: #e7f5ff;
    border: 2px solid var(--blue);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.82rem;
    color: #1877f2;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
}

/* ── Level ball ──────────────────────────────────── */
.header-level-ball {
    width: 22px;
    height: 22px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.header-level-num {
    font-size: 0.7rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.profile-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.profile-level-ball {
    width: 28px;
    height: 28px;
    object-fit: contain;
    image-rendering: pixelated;
}

.profile-level-num {
    font-size: 0.8rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 2px 7px;
}

.xp-ball-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    image-rendering: pixelated;
    vertical-align: middle;
    margin-right: 3px;
}

/* ── Profile card top row (avatar + info) ────────────────────────────────── */
.profile-card-top {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
}

.profile-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.profile-avatar-img {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    object-fit: contain;
    background: rgba(0, 0, 0, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.35);
    image-rendering: pixelated;
}

.profile-avatar-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.profile-edit-btn {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    background: #111;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    color: white;
    font-size: 0.65rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    min-width: unset;
    box-shadow: none;
    text-transform: none;
    line-height: 1;
}

.profile-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.profile-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.profile-title {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.82rem;
    opacity: 0.92;
}

.profile-title-edit-btn {
    background: rgba(0, 0, 0, 0.55);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.65rem;
    cursor: pointer;
    padding: 2px 5px;
    min-width: unset;
    width: auto;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    text-transform: none;
    line-height: 1;
    letter-spacing: 0;
    font-weight: normal;
    transition: background var(--t), border-color var(--t);
}

.profile-title-edit-btn:hover {
    background: rgba(0, 0, 0, 0.75);
    border-color: rgba(255, 255, 255, 0.6);
    transform: none;
    box-shadow: none;
}

/* ── Pokédex button in profile ───────────────────────────────────────────── */
.profile-pokedex-btn {
    width: 100%;
    background: #f4f4f8;
    border: 2px solid #e0e0e8;
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 4px;
    transition: background var(--t), border-color var(--t), transform var(--t);
    box-shadow: none;
    text-transform: none;
}

.profile-pokedex-btn:hover {
    background: #e8e8f0;
    border-color: var(--red);
    transform: translateY(-1px);
    box-shadow: none;
}

.profile-pokedex-count {
    font-size: 0.82rem;
    color: var(--red);
    font-weight: 900;
}

/* ── Stats tabs ──────────────────────────────────────────────────────────── */
.profile-tabs {
    display: flex;
    gap: 4px;
    margin: 8px 0 4px;
}

.profile-tab {
    flex: 1;
    background: #f4f4f8;
    border: 2px solid #e0e0e8;
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #888;
    cursor: pointer;
    transition: background var(--t), color var(--t), border-color var(--t);
    min-width: unset;
    box-shadow: none;
    text-transform: none;
}

.profile-tab.active {
    background: var(--red);
    border-color: var(--red-dark, #b71c1c);
    color: white;
}

.profile-tab-content.hidden {
    display: none;
}

/* ── Avatar selection modal ──────────────────────────────────────────────── */
.avatar-modal-box {
    max-height: 80vh;
    overflow-y: auto;
}

.avatar-section-header {
    font-size: 0.78rem;
    font-weight: 800;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 12px 0 6px;
    padding: 0 2px;
}

.avatar-select-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.avatar-select-item {
    background: #f4f4f8;
    border: 2px solid #e0e0e8;
    border-radius: 10px;
    padding: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: border-color var(--t), background var(--t), transform var(--t);
    min-width: unset;
    width: 100%;
    box-shadow: none;
    text-transform: none;
    aspect-ratio: 1;
}

.avatar-select-item img {
    width: 100%;
    height: auto;
    object-fit: contain;
    image-rendering: pixelated;
}

.avatar-select-item:hover {
    border-color: var(--red);
    background: #fff0f0;
    transform: scale(1.08);
    box-shadow: none;
}

.avatar-select-item.selected {
    border-color: var(--red);
    background: #ffebeb;
    box-shadow: 0 0 0 2px var(--red);
}

.avatar-shiny-badge {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: 0.55rem;
    line-height: 1;
    pointer-events: none;
}

/* ── Title selection modal ───────────────────────────────────────────────── */
.title-select-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 4px;
    max-height: 60vh;
    overflow-y: auto;
}

.title-select-section-header {
    font-size: 0.72rem;
    font-weight: 800;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 2px 2px;
    border-bottom: 1px solid #e8e8e8;
    margin-top: 4px;
}

.title-select-section-header:first-child {
    margin-top: 0;
    padding-top: 4px;
}

.title-select-item {
    background: #f4f4f8;
    border: 2px solid #e0e0e8;
    border-radius: var(--radius);
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color var(--t), background var(--t);
    min-width: unset;
    box-shadow: none;
    text-transform: none;
    width: 100%;
    text-align: left;
}

.title-select-item:hover {
    border-color: var(--red);
    background: #fff0f0;
    box-shadow: none;
    transform: none;
}

.title-select-item.selected {
    border-color: var(--red);
    background: #ffebeb;
}

.title-select-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #333;
}

@media (max-width: 480px) {
    .avatar-select-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ── Profile account actions ────────────────────────────────────────────── */
.profile-account-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.profile-action-btn {
    flex: 1;
    padding: 9px 6px;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 10px;
    border: 2px solid #ccc;
    background: #f5f5f5;
    color: #444;
    box-shadow: 0 3px 0 #ccc;
    cursor: pointer;
    transition: filter 0.15s;
}

.profile-action-btn:hover {
    filter: brightness(0.96);
}

.profile-action-btn--danger {
    background: #fff0f0;
    border-color: #f99;
    color: #c0392b;
    box-shadow: 0 3px 0 #f99;
}