.player-profile-dialog,
.profile-edit-dialog,
.history-dialog {
    width:min(100%,440px);
    color:#f5e6c8;
    background:
        radial-gradient(circle at 50% 0,rgba(217,157,65,.14),transparent 34%),
        linear-gradient(145deg,#4b3b31,#241d19 70%);
}

.player-profile-dialog,
.profile-edit-dialog {
    transform:translate3d(var(--profile-drag-x,0),var(--profile-drag-y,0),0);
    will-change:transform;
}
.player-profile-dialog .dialog-title,
.profile-edit-dialog .dialog-title {
    cursor:grab;
    touch-action:none;
    user-select:none;
    -webkit-user-select:none;
}
.player-profile-dialog .dialog-title.dragging,
.profile-edit-dialog .dialog-title.dragging { cursor:grabbing; }

.player-profile-card { display:grid;gap:13px; }
.profile-identity {
    display:grid;
    grid-template-columns:82px 1fr;
    gap:14px;
    align-items:center;
    padding:13px;
    border:1px solid rgba(235,190,100,.4);
    border-radius:14px;
    background:linear-gradient(120deg,rgba(12,8,6,.6),rgba(87,53,28,.38));
    box-shadow:inset 0 1px rgba(255,231,173,.09),0 7px 18px rgba(0,0,0,.3);
}
.profile-main-avatar,
.profile-edit-avatar {
    position:relative;
    display:grid;
    overflow:hidden;
    place-items:center;
    border:3px solid #e3ad4f;
    border-radius:50%;
    color:#2c1b10;
    background:linear-gradient(145deg,#fff0b0,#c97c25);
    box-shadow:0 0 0 3px rgba(70,39,18,.9),0 5px 14px rgba(0,0,0,.45);
    font:900 28px/1 Georgia,serif;
}
.profile-main-avatar { width:78px;height:78px; }
.profile-edit-avatar { width:88px;height:88px;margin:4px auto 13px; }
.profile-main-avatar img,
.profile-edit-avatar img { width:100%;height:100%;object-fit:cover; }
.profile-rank { display:flex;gap:7px;align-items:center;color:#e7b95f;font:700 13px system-ui,sans-serif; }
.profile-rank::before { content:'⚑';color:#ffd45c; }
.profile-identity h2 { margin:5px 0 2px;color:#fff2d4;font:800 22px/1.1 Georgia,serif; }
.profile-status-line { margin:0;color:#cbb89b;font:12px/1.35 system-ui,sans-serif; }
.profile-resource-row { display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;color:#f3c96b;font:700 12px system-ui,sans-serif; }
.profile-resource-row span { padding:4px 8px;border:1px solid rgba(226,173,77,.25);border-radius:12px;background:rgba(0,0,0,.24); }

.profile-progress { padding:1px 4px; }
.profile-progress-label { display:flex;justify-content:space-between;margin-bottom:6px;color:#d5bf9d;font:700 11px system-ui,sans-serif; }
.profile-progress-track { height:10px;overflow:hidden;border:1px solid #6c4327;border-radius:8px;background:#2a1b14;box-shadow:inset 0 2px 4px #000; }
.profile-progress-track span { display:block;height:100%;width:0;border-radius:inherit;background:linear-gradient(90deg,#ffbb22,#ed7a26);box-shadow:0 0 12px rgba(255,171,43,.6);transition:width .5s ease; }

.profile-stats { display:grid;grid-template-columns:repeat(4,1fr);overflow:hidden;border:1px solid #6a5140;border-radius:11px;background:rgba(15,10,8,.35); }
.profile-stat { padding:10px 4px;text-align:center;border-right:1px solid #60493b; }
.profile-stat:last-child { border-right:0; }
.profile-stat strong { display:block;color:#ffc85b;font:900 18px/1 Georgia,serif; }
.profile-stat small { color:#bca68f;font:10px system-ui,sans-serif;text-transform:uppercase;letter-spacing:.05em; }
.profile-actions { display:grid;grid-template-columns:1fr 1fr;gap:10px; }
.profile-action-button {
    min-height:46px;
    border:2px solid #9a652f;
    border-radius:8px;
    color:#3d2515;
    background:linear-gradient(#f0c17d,#a65d2d);
    box-shadow:inset 0 1px #ffe0a9,0 4px 0 #4a2817;
    font:800 14px Georgia,serif;
    cursor:pointer;
}
.profile-action-button.secondary { color:#f4dfbd;background:linear-gradient(#73543b,#3e2c22); }
.profile-action-button:active { transform:translateY(2px);box-shadow:inset 0 1px #ffe0a9,0 2px 0 #4a2817; }
.profile-actions[hidden],.profile-connected-copy[hidden] { display:none!important; }
.profile-connected-copy { margin:0;color:#d6c19e;text-align:center;font:12px/1.4 system-ui,sans-serif; }

.profile-edit-form { display:grid;gap:12px; }
.profile-avatar-toolbar { display:grid;grid-template-columns:1fr 1fr;gap:8px; }
.profile-upload-button,.profile-provider-button {
    display:grid;min-height:40px;place-items:center;padding:8px;border:1px solid #9c6a39;border-radius:7px;
    color:#f0d5a8;background:#392820;font:700 12px system-ui,sans-serif;cursor:pointer;
}
.profile-upload-button input { position:absolute;width:1px;height:1px;opacity:0;pointer-events:none; }
.profile-form-grid { display:grid;grid-template-columns:1fr 1fr;gap:10px; }
.profile-field { display:grid;gap:5px; }
.profile-field.full { grid-column:1/-1; }
.profile-field span { color:#ddb467;font:700 12px system-ui,sans-serif; }
.profile-field input,.profile-field select,.history-filter input,.history-filter select {
    width:100%;min-width:0;height:42px;padding:0 10px;border:2px solid #705949;border-radius:7px;
    color:#f5e9d5;background:#211b18;box-shadow:inset 0 2px 5px rgba(0,0,0,.55);font:14px system-ui,sans-serif;
}
.profile-field input:focus,.profile-field select:focus,.history-filter input:focus,.history-filter select:focus { outline:2px solid rgba(229,168,70,.42);border-color:#d49a43; }
.profile-char-count { margin-top:-2px;color:#9d8b77;text-align:right;font:10px system-ui,sans-serif; }
.avatar-section-title { margin:2px 0 -3px;color:#e6bd72;font:800 12px system-ui,sans-serif;text-transform:uppercase;letter-spacing:.07em; }
.avatar-picker { display:grid;grid-template-columns:repeat(5,1fr);gap:7px; }
.avatar-choice { position:relative;aspect-ratio:1;padding:0;overflow:hidden;border:2px solid #624b3b;border-radius:50%;background:#17110f;cursor:pointer; }
.avatar-choice img { width:100%;height:100%;display:block;object-fit:cover;pointer-events:none; }
.avatar-choice.selected { border-color:#ffcc55;box-shadow:0 0 0 2px #6a3e18,0 0 14px rgba(255,184,50,.55);transform:scale(1.05); }
.avatar-choice.selected::after { content:'✓';position:absolute;right:0;bottom:0;display:grid;width:19px;height:19px;place-items:center;border-radius:50%;color:#2b1b0c;background:#ffd45e;font:900 12px system-ui; }
.profile-form-status,.history-status { min-height:18px;margin:0;color:#d4bd9c;text-align:center;font:12px/1.4 system-ui,sans-serif; }
.profile-form-status.error,.history-status.error { color:#ff9b8f; }
.profile-form-status.success { color:#9ee39a; }
.profile-form-actions { display:grid;grid-template-columns:1fr 1fr;gap:9px; }
.profile-save-button,.profile-cancel-button,.history-find-button {
    min-height:44px;border:2px solid #98602e;border-radius:7px;color:#402414;background:linear-gradient(#efbe78,#a75d2c);font:800 14px Georgia,serif;cursor:pointer;
}
.profile-cancel-button { color:#f7d9d2;border-color:#883e3e;background:linear-gradient(#b34a51,#6c252b); }
.profile-save-button:disabled { opacity:.55;cursor:wait; }

.history-filters { display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:11px; }
.history-filter { display:grid;gap:4px; }
.history-filter span { color:#d8ad66;font:700 10px system-ui,sans-serif;text-transform:uppercase; }
.history-find-button { align-self:end; }
.history-list { display:grid;gap:7px;min-height:160px; }
.history-card {
    display:grid;grid-template-columns:50px 1fr auto;gap:10px;align-items:center;padding:9px;
    border:1px solid #655044;border-radius:9px;background:linear-gradient(100deg,rgba(90,69,55,.72),rgba(35,28,24,.85));cursor:pointer;
}
.history-card:hover,.history-card:focus { border-color:#d29542;outline:0; }
.history-avatar { display:grid;width:46px;height:46px;overflow:hidden;place-items:center;border:2px solid #bd8439;border-radius:50%;background:#251a2c;color:#f0d393;font:800 16px Georgia; }
.history-avatar img { width:100%;height:100%;object-fit:cover; }
.history-opponent { min-width:0; }
.history-opponent strong { display:block;overflow:hidden;color:#f5e5ca;text-overflow:ellipsis;white-space:nowrap;font:800 14px Georgia,serif; }
.history-opponent small { display:block;margin-top:4px;color:#bfa88c;font:11px system-ui,sans-serif; }
.history-result { min-width:54px;text-align:right; }
.history-result strong { display:block;font:900 12px system-ui,sans-serif;text-transform:uppercase; }
.history-result small { color:#bb9f7b;font:10px system-ui,sans-serif; }
.history-card.win .history-result strong { color:#8ee28c; }
.history-card.draw .history-result strong { color:#ffd46d; }
.history-card.loss .history-result strong { color:#ff8f84; }
.history-empty { display:grid;min-height:180px;place-items:center;padding:20px;color:#a9957e;text-align:center;font:13px/1.5 system-ui,sans-serif; }
.history-pagination { display:flex;justify-content:center;gap:8px;margin-top:10px; }
.history-pagination button { min-width:88px;height:36px;border:1px solid #8c6138;border-radius:6px;color:#f0d5aa;background:#3a2920; }
.history-pagination button:disabled { opacity:.35; }
.history-detail { margin-top:10px;padding:12px;border:1px solid #7e5a37;border-radius:10px;background:rgba(11,8,6,.48); }
.history-detail[hidden] { display:none; }
.history-detail-head { display:flex;justify-content:space-between;gap:8px;align-items:center; }
.history-detail h3 { margin:0;color:#f2ca79;font:800 15px Georgia,serif; }
.history-detail-close { border:0;color:#ead4b5;background:transparent;font-size:20px;cursor:pointer; }
.history-detail-grid { display:grid;grid-template-columns:1fr 1fr;gap:7px;margin-top:10px; }
.history-detail-grid span { padding:7px;border-radius:6px;color:#cbb597;background:rgba(255,255,255,.04);font:11px system-ui,sans-serif; }
.history-pgn { max-height:120px;margin:9px 0 0;padding:8px;overflow:auto;border-radius:6px;color:#d8c8b2;background:#171310;white-space:pre-wrap;font:10px/1.45 ui-monospace,monospace; }

@media (max-width:380px) {
    .player-profile-dialog,.profile-edit-dialog,.history-dialog { padding-right:11px;padding-left:11px; }
    .profile-stats { grid-template-columns:repeat(2,1fr); }
    .profile-stat:nth-child(2) { border-right:0; }
    .profile-stat:nth-child(-n+2) { border-bottom:1px solid #60493b; }
    .profile-form-grid,.history-filters { grid-template-columns:1fr; }
    .profile-field.full { grid-column:auto; }
    .avatar-picker { gap:5px; }
}
