/* Keep both rank panels stretched while the editor opens in a modal. */
@media (min-width:1024px) {
  #profile-dashboard:has(#nearby-ranks) { align-items:stretch; grid-template-columns:minmax(0,.95fr) minmax(0,1.35fr); }
  #profile-dashboard > #nearby-ranks { grid-column:1; align-self:stretch; margin-block:0; }
  #profile-dashboard:has(#nearby-ranks) > .profile-card-panel { grid-column:2; align-self:stretch; height:auto; margin-block:0; }
}
#profile-dashboard > .profile-card-panel { grid-template-rows:auto auto auto; align-content:start; }
#profile-dashboard > .profile-card-panel .profile-rank-layout { align-content:start; }
#profile-dashboard .profile-customization-toggle { width:100%; min-height:40px; padding:.5rem 1.1rem; text-align:left; justify-content:space-between; border-radius:0!important; }
#rank-customization-toggle[hidden] { display:none!important; }
#rank-customization-toggle:is(:hover,:focus-visible) { background:var(--surface-hover,#404249)!important; color:var(--text,#fff); }
#rank-customization-dialog { width:min(760px,calc(100vw - 32px)); max-height:calc(100svh - 32px); padding:0; border-radius:0!important; overflow:auto; }
#rank-customization-dialog::backdrop { background:rgba(0,0,0,.65); }
#rank-customization-dialog .profile-customization { display:grid; gap:16px; margin:0; padding:20px; width:100%; min-width:0; box-sizing:border-box; background:var(--surface,#2b2d31); border:0; border-radius:0!important; }
#rank-customization-dialog .profile-customization[hidden] { display:none; }
#rank-customization-dialog .profile-section-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; }
#rank-customization-dialog h2 { margin:0; font-size:1.25rem; }
#rank-customization-dialog .profile-color-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
#rank-customization-dialog .profile-editor-toolbar { display:flex; flex-wrap:wrap; gap:.8rem; }
#rank-customization-dialog .profile-editor-actions { flex-wrap:wrap; margin-left:0; }
#rank-customization-dialog :is(button,input,select), #rank-customization-toggle { border-radius:0!important; transition:background-color 180ms ease,border-color 180ms ease,color 180ms ease,box-shadow 180ms ease,transform 90ms ease!important; }
#rank-customization-dialog button:active, #rank-customization-toggle:active { transform:translateY(1px)!important; }
#rank-customization-dialog .profile-color-trigger:is(:hover,:focus-visible) { background:var(--surface-hover,#404249)!important; border-color:var(--interactive,#939bff); }
#rank-customization-dialog :focus-visible, #rank-customization-toggle:focus-visible { outline:2px solid var(--interactive,#939bff); outline-offset:3px; }
#rank-customization-dialog .profile-customization-close, #profile-reward-dialog .studio-icon-button { background:#da373c!important; border-color:#da373c!important; color:#fff!important; }
#rank-customization-dialog .profile-customization-close:is(:hover,:focus-visible), #profile-reward-dialog .studio-icon-button:is(:hover,:focus-visible) { background:#f04b50!important; border-color:#f04b50!important; }
#rank-customization-dialog .profile-customization-close:active, #profile-reward-dialog .studio-icon-button:active { background:#a92329!important; border-color:#a92329!important; }
@media(max-width:480px) { #rank-customization-dialog .profile-customization { padding:16px; } #rank-customization-dialog .profile-color-grid { grid-template-columns:1fr; } }
@media(prefers-reduced-motion:reduce) { #rank-customization-dialog :is(button,input,select), #rank-customization-toggle { transition:none!important; transform:none!important; } }
/* The mirror follows the original renderer; no second editor or controller. */
#rank-customization-dialog .profile-customization-preview { min-width:0; overflow:auto; }
#rank-customization-dialog .profile-customization-preview .profile-rank-preview { width:100%; box-sizing:border-box; }
#rank-customization-toggle .bi-arrow-right { transition:transform 180ms ease!important; }
#rank-customization-toggle:is(:hover,:focus-visible) .bi-arrow-right { transform:translateX(4px); }
/* Keep secondary controls neutral, including their hover and press feedback. */
#rank-customization-dialog :is(.studio-button,.profile-color-trigger):not(:disabled) { background:var(--surface-strong,#35373c)!important; border-color:var(--border,#4e5058); color:var(--text,#fff)!important; }
#rank-customization-dialog :is(.studio-button,.profile-color-trigger):is(:hover,:focus-visible):not(:disabled) { background:var(--surface-hover,#4e5058)!important; border-color:var(--muted,#b5bac1); }
#rank-customization-dialog :is(.studio-button,.profile-color-trigger):active:not(:disabled) { background:#292b30!important; }
#rank-customization-dialog button:disabled { opacity:.65; cursor:not-allowed; }
#rank-customization-dialog :is(.profile-color-preset,[data-preset]):is(:hover,:focus-visible) { box-shadow:0 0 0 3px #939bff!important; filter:brightness(1.15); }
/* cqw values must resolve against the mirrored card's width, as in the original. */
#rank-customization-dialog .profile-customization-preview { container-type:inline-size; overflow:visible; align-self:start; }
#rank-customization-dialog .profile-customization-options { display:grid; gap:16px; min-width:0; }
@media(min-width:768px) {
  #rank-customization-dialog { width:min(1100px,calc(100vw - 32px)); }
  #rank-customization-dialog .profile-customization { grid-template-columns:minmax(0,1.25fr) minmax(0,1fr); align-items:start; gap:20px; }
  #rank-customization-dialog .profile-section-heading { grid-column:1 / -1; }
  #rank-customization-dialog .profile-editor-toolbar { display:grid; grid-template-columns:minmax(0,1fr); }
  #rank-customization-dialog .profile-background-upload { display:flex; flex-wrap:wrap; }
  #rank-customization-dialog .profile-background-details { grid-row:auto; white-space:normal; }
  #rank-customization-dialog .profile-editor-actions { grid-column:auto; grid-row:auto; flex-wrap:wrap; justify-self:start; }
}
@media(prefers-reduced-motion:reduce) { #rank-customization-toggle .bi-arrow-right { transition:none; transform:none!important; } }
/* Modal actions retain readable labels instead of the inline panel's icon-only mode. */
#rank-customization-dialog .profile-editor-toolbar { display:flex; flex-direction:column; align-items:stretch; }
#rank-customization-dialog .profile-background-upload { display:flex; flex-wrap:wrap; }
#rank-customization-dialog .profile-background-details { display:flex; flex-wrap:wrap; white-space:normal; font-size:.75rem; }
#rank-customization-dialog .profile-editor-actions { display:flex; flex-wrap:wrap; margin:0; grid-column:auto; grid-row:auto; }
#rank-customization-dialog .profile-editor-toolbar .studio-button { flex:0 1 auto; width:auto; min-width:0; padding:.5rem .65rem; font-size:.8rem; }
#rank-customization-dialog .profile-editor-toolbar .profile-action-label { display:inline; }

/* Keep the background upload beneath the card; save/reset follow the options. */
#rank-customization-dialog .profile-customization-card-column { display:grid; gap:16px; min-width:0; align-self:start; }
#rank-customization-dialog .profile-background-details { min-width:0; overflow-wrap:anywhere; }
#rank-customization-dialog .profile-editor-toolbar .profile-background-upload { align-items:center; }

#rank-customization-dialog .profile-customization-preview { position:relative; }

/* Match the site's restrained success/danger button treatments. */
#rank-customization-dialog .profile-editor-actions .studio-button { min-width:0; padding:.5rem .65rem; font-size:.8rem; }
#rank-customization-dialog .profile-editor-actions .profile-action-label { display:inline; }
#rank-customization-dialog .profile-editor-actions button[type=submit] { background:#30443b!important; border-color:#456b56; }
#rank-customization-dialog .profile-editor-actions button[type=submit]:is(:hover,:focus-visible) { background:#3b5949!important; border-color:#68a17e; }
#rank-customization-dialog #reset-rank-card { background:#473438!important; border-color:#71484e; }
#rank-customization-dialog #reset-rank-card:is(:hover,:focus-visible) { background:#604047!important; border-color:#aa646e; }
/* Discrete display/overlay transitions retain the native popover during its exit.
   The controller still owns hidden state, focus restoration and light dismiss. */
#profile-color-picker {
  opacity:1; transform:translateY(0) scale(1); transform-origin:top right;
  transition:opacity 160ms ease,transform 160ms ease,display 160ms allow-discrete,overlay 160ms allow-discrete!important;
}
#profile-color-picker[hidden], #profile-color-picker[popover]:not(:popover-open) { opacity:0; transform:translateY(-6px) scale(.98); }
@starting-style { #profile-color-picker:not([hidden]) { opacity:0; transform:translateY(-6px) scale(.98); } }
:is(.profile-customization-close,.profile-color-close,#close-rank-card,#profile-reward-dialog .studio-icon-button) .bi-x-lg { display:inline-block; transition:transform 180ms ease!important; }
:is(.profile-customization-close,.profile-color-close,#close-rank-card,#profile-reward-dialog .studio-icon-button):is(:hover,:focus-visible) .bi-x-lg { transform:rotate(90deg) scale(1.1); }
@media(prefers-reduced-motion:reduce) {
  #profile-color-picker { transition:none!important; transform:none!important; }
  :is(.profile-customization-close,.profile-color-close,#close-rank-card,#profile-reward-dialog .studio-icon-button) .bi-x-lg { transition:none!important; transform:none!important; }
}

/* Keep draft, reset and save in one compact row at every dialog width. */
#rank-customization-dialog .profile-editor-actions { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; width:100%; justify-self:stretch; }
#rank-customization-dialog .profile-editor-actions .studio-button { display:flex; align-items:center; justify-content:center; gap:5px; width:100%; min-width:0; min-height:36px; height:36px; box-sizing:border-box; padding:5px 8px; font-size:.75rem; line-height:1.2; white-space:nowrap; }
@media(min-width:768px) and (max-width:1023px) {
  #rank-customization-dialog .profile-editor-actions { gap:6px; }
  #rank-customization-dialog .profile-editor-actions .studio-button { padding:5px 4px; }
  #rank-customization-dialog .profile-editor-actions .bi { display:none; }
}
