:root {
    --profile-bg: rgba(22, 22, 27, 0.97);
    --profile-panel: rgba(32, 32, 39, 0.9);
    --profile-border: rgba(90, 90, 100, 0.45);
    --profile-text: #e9e9ec;
    --profile-muted: #9d9da6;
    --profile-accent: #1fb98f;
    --profile-accent-soft: rgba(31, 185, 143, 0.15);
}

.user-profile-root {
    position: fixed;
    top: 1.2%;
    right: 1.2%;
    z-index: 1200;
    font-family: Arial, sans-serif;
}

.user-profile-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--profile-bg);
    border: 1px solid var(--profile-border);
    border-radius: 16px;
    padding: 6px 9px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

.user-profile-rank {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #dcb352;
    font-size: 20px;
    line-height: 1;
}

.user-profile-rank-value {
    color: var(--profile-text);
    font-size: 20px;
    font-weight: 700;
}

.user-profile-trigger-btn {
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    border-radius: 999px;
    padding: 2px;
}

.user-profile-avatar-shell {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #111219;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.user-profile-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-profile-avatar-fallback {
    color: #f2f2f4;
    font-size: 18px;
    font-weight: 700;
}

.user-profile-online-dot {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--profile-accent);
    border: 2px solid #111219;
}

.user-profile-menu {
    width: 26%;
    min-width: 320px;
    max-width: 380px;
    max-height: calc(100vh - 100px);
    margin-top: 8px;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--profile-border);
    background: linear-gradient(150deg, rgba(28, 28, 35, 0.97), rgba(23, 23, 29, 0.97));
    color: var(--profile-text);
    box-shadow: 0 25px 55px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(12px);
    transform-origin: top right;
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.user-profile-menu::-webkit-scrollbar {
    display: none;
}

.user-profile-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.user-profile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.user-profile-large-avatar {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.08);
    background: #090a0f;
    overflow: hidden;
    cursor: pointer;
}

.user-profile-large-avatar:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.user-profile-title {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 700;
}

.user-profile-status {
    margin: 2px 0 0;
    color: var(--profile-muted);
    font-size: 1rem;
}

.user-profile-section {
    margin-top: 10px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(50, 50, 60, 0.7);
    transition: all 0.2s ease;
    cursor: pointer;
}

.user-profile-section:hover {
    background: rgba(60, 70, 85, 0.95);
    border-color: rgba(31, 185, 143, 0.4);
    box-shadow: 0 0 16px rgba(31, 185, 143, 0.2), inset 0 0 8px rgba(31, 185, 143, 0.05);
    transform: translateY(-1px);
}

.user-profile-section h4 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.user-profile-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
}

.user-profile-row label {
    font-size: 0.9rem;
    color: var(--profile-muted);
}

.user-profile-row input,
.user-profile-row .readonly {
    flex: 1;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(17, 17, 24, 0.75);
    color: var(--profile-text);
    padding: 0.45em 0.55em;
    font-size: 0.9rem;
    min-width: 0;
}

.user-profile-row .readonly {
    border-style: dashed;
}

.user-profile-actions {
    display: grid;
    gap: 6px;
    margin-top: 6px;
}

.user-profile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(20, 20, 26, 0.85);
    color: var(--profile-text);
    padding: 0.6em 0.75em;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

@media (max-width: 900px) {
    .user-profile-menu {
        width: 42%;
        min-width: 280px;
    }
}

@media (max-width: 640px) {
    .user-profile-root {
        top: 1%;
        right: 1%;
        left: 1%;
    }

    .user-profile-menu {
        width: calc(100% - 2rem);
        min-width: 0;
        max-width: none;
    }
}

.user-profile-btn:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(28, 28, 37, 0.95);
}

.user-profile-btn.primary {
    border-color: rgba(31, 185, 143, 0.55);
    background: var(--profile-accent-soft);
}

.user-profile-btn.danger {
    border-color: rgba(203, 72, 72, 0.6);
    color: #fcb7b7;
}

.user-profile-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.user-profile-settings-placeholder {
    color: var(--profile-muted);
    font-size: 13px;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
}

.user-profile-note {
    margin-top: 8px;
    color: var(--profile-muted);
    font-size: 12px;
}

.user-profile-hidden-input {
    display: none;
}

.user-profile-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1300;
}

.user-profile-modal-backdrop.open {
    display: flex;
}

.user-profile-modal {
    width: min(440px, calc(100vw - 28px));
    background: linear-gradient(170deg, rgba(29, 29, 38, 0.98), rgba(21, 21, 27, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 20px;
    color: var(--profile-text);
}

.user-profile-modal h3 {
    margin: 0 0 12px;
    font-size: 30px;
}

.user-profile-modal-group {
    margin-bottom: 12px;
}

.user-profile-modal-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 20px;
    color: var(--profile-muted);
}

.user-profile-modal-group input {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(15, 15, 21, 0.8);
    color: var(--profile-text);
    font-size: 20px;
}

.user-profile-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.user-profile-toast-wrap {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1350;
    display: grid;
    gap: 8px;
}

.user-profile-toast {
    min-width: 220px;
    max-width: 300px;
    background: rgba(25, 25, 32, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-left: 4px solid #6c6cff;
    color: #efeff2;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 16px;
    animation: profile-toast-in 0.18s ease;
}

.user-profile-toast.success {
    border-left-color: #1fb98f;
}

.user-profile-toast.error {
    border-left-color: #d96b6b;
}

@keyframes profile-toast-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 700px) {
    .user-profile-root {
        right: 10px;
        top: 10px;
    }

    .user-profile-menu {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 74px);
        overflow: auto;
    }

    .user-profile-title {
        font-size: 26px;
    }

    .user-profile-status,
    .user-profile-row input,
    .user-profile-row .readonly,
    .user-profile-row label,
    .user-profile-btn,
    .user-profile-section h4,
    .user-profile-modal h3,
    .user-profile-modal-group label,
    .user-profile-modal-group input {
        font-size: 16px;
    }
}

/* Public Profile Modal Styles */
.public-profile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    font-family: Arial, sans-serif;
}

.public-profile-overlay[style*="display: flex"] {
    display: flex;
}

.public-profile-modal {
    position: relative;
    width: min(500px, calc(100vw - 32px));
    max-height: 85vh;
    background: linear-gradient(170deg, rgba(29, 29, 38, 0.98), rgba(21, 21, 27, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 28px;
    color: var(--profile-text);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.public-profile-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--profile-text);
    font-size: 32px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.public-profile-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.public-profile-content {
    margin-top: 0;
}

.public-profile-loading,
.public-profile-error {
    text-align: center;
    padding: 40px 20px;
    color: var(--profile-muted);
}

.public-profile-error {
    color: #d96b6b;
}

.public-profile-header {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.public-profile-avatar-section {
    flex-shrink: 0;
}

.public-profile-avatar-img,
.public-profile-avatar-fallback {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #090a0f;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.public-profile-avatar-img {
    object-fit: cover;
}

.public-profile-avatar-fallback {
    font-size: 40px;
    font-weight: 700;
    color: var(--profile-text);
}

.public-profile-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.public-profile-username {
    margin: 0 0 6px;
    font-size: 26px;
    font-weight: 700;
    color: var(--profile-text);
}

.public-profile-join-date {
    margin: 0;
    font-size: 14px;
    color: var(--profile-muted);
}

.public-profile-stats-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.public-profile-stat-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.public-profile-stat-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    transition: background-color 0.2s;
}

.public-profile-stat-card:hover {
    background: rgba(255, 255, 255, 0.08);
}

.public-profile-stat-label {
    font-size: 12px;
    color: var(--profile-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.public-profile-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--profile-text);
}

.public-profile-stat-value.wins {
    color: #1fb98f;
}

.public-profile-stat-value.losses {
    color: #d96b6b;
}

.public-profile-stat-value.draws {
    color: #6c6cff;
}

.public-profile-stat-value.rank-badge {
    font-size: 16px;
    display: inline-block;
    padding: 4px 12px;
    background: rgba(31, 185, 143, 0.15);
    border: 1px solid rgba(31, 185, 143, 0.4);
    border-radius: 20px;
    color: var(--profile-accent);
}

.public-profile-progress-bar {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 14px;
}

.public-profile-progress-label {
    font-size: 12px;
    color: var(--profile-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

.public-profile-progress-container {
    display: flex;
    height: 24px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.3);
}

.public-profile-progress-wins {
    background: #1fb98f;
    min-width: 12px;
}

.public-profile-progress-losses {
    background: #d96b6b;
    min-width: 12px;
}

.public-profile-progress-text {
    font-size: 13px;
    color: var(--profile-muted);
    text-align: center;
}

/* Profile Stats Component Styles */
.profile-stats-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-stats-main-grid,
.profile-stats-secondary-grid,
.profile-stats-streak-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 8px;
}

.profile-stat-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    transition: background-color 0.2s;
}

.profile-stat-card:hover {
    background: rgba(255, 255, 255, 0.08);
}

.profile-stat-label {
    font-size: 11px;
    color: var(--profile-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.profile-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--profile-text);
}

.profile-stat-value.wins {
    color: #1fb98f;
}

.profile-stat-value.losses {
    color: #d96b6b;
}

.profile-stat-value.draws {
    color: #6c6cff;
}

.profile-stat-value.rank-badge {
    font-size: 12px;
    display: inline-block;
    padding: 3px 8px;
    background: rgba(31, 185, 143, 0.15);
    border: 1px solid rgba(31, 185, 143, 0.4);
    border-radius: 12px;
    color: var(--profile-accent);
    font-weight: 600;
}

.profile-stats-chart {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
    margin-top: 4px;
}

.profile-stats-chart-title {
    font-size: 11px;
    color: var(--profile-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.profile-stats-bar-container {
    display: flex;
    height: 20px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
    background: rgba(0, 0, 0, 0.3);
}

.profile-stats-bar-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    position: relative;
}

.profile-stats-bar-section.wins {
    background: #1fb98f;
}

.profile-stats-bar-section.losses {
    background: #d96b6b;
}

.profile-stats-bar-section.draws {
    background: #6c6cff;
}

.profile-stats-bar-label {
    font-size: 10px;
    color: white;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.profile-stats-bar-text {
    font-size: 11px;
    color: var(--profile-muted);
    text-align: center;
}

/* Responsive Design */
@media (max-width: 640px) {
    .public-profile-modal {
        width: calc(100vw - 20px);
        max-height: 90vh;
        padding: 20px;
    }

    .public-profile-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 16px;
    }

    .public-profile-avatar-img,
    .public-profile-avatar-fallback {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }

    .public-profile-username {
        font-size: 22px;
    }

    .public-profile-stat-group {
        grid-template-columns: repeat(2, 1fr);
    }

    .public-profile-stat-value {
        font-size: 20px;
    }

    .profile-stats-main-grid,
    .profile-stats-secondary-grid,
    .profile-stats-streak-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .profile-stat-value {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .public-profile-modal {
        width: calc(100vw - 16px);
        padding: 16px;
    }

    .public-profile-close {
        width: 28px;
        height: 28px;
        font-size: 24px;
    }

    .public-profile-avatar-img,
    .public-profile-avatar-fallback {
        width: 70px;
        height: 70px;
        font-size: 28px;
    }

    .public-profile-username {
        font-size: 20px;
    }

    .public-profile-stat-group {
        grid-template-columns: 1fr;
    }

    .profile-stats-main-grid,
    .profile-stats-secondary-grid,
    .profile-stats-streak-grid {
        grid-template-columns: 1fr;
    }
}


/* ── Responsive: 1920×1080 / 15.6" ── */
@media (max-width: 1600px) {
    .profileModal { max-width: min(820px, 94vw); }
}
@media (max-width: 1280px) {
    .profileModal { max-width: min(720px, 96vw); padding: 0; }
    .statsGrid { grid-template-columns: repeat(2, 1fr); }
}

/* Global responsive baseline */
html {
    font-size: clamp(14px, 0.24vw + 12.9px, 18px);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

/* Global chat-style typography override */
:root {
    --global-chat-font: 'JetBrains Mono', monospace;
}

html,
body,
body * {
    font-family: var(--global-chat-font) !important;
}
