.user-profile-dialog {
  width: min(580px, calc(100% - (var(--space-lg) * 2)));
  padding: 0;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: 0 28px 80px rgba(6, 31, 64, 0.26);
  overflow: hidden;
}

.user-profile-dialog:focus,
.user-profile-dialog:focus-visible {
  outline: none;
}

.user-profile-dialog::backdrop {
  background: rgba(6, 31, 64, 0.48);
}

.user-profile-dialog-header {
  display: none;
}

.user-profile-hero-content {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 0;
}

.user-profile-dialog-hero {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl);
  border-bottom: var(--border-width) solid var(--color-border);
}

.user-profile-avatar,
.user-profile-avatar-placeholder {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: 999px;
  clip-path: circle(48% at 50% 50%);
  border: 0;
  box-shadow: 0 6px 20px rgba(6, 31, 64, 0.14);
}

.user-profile-avatar {
  object-fit: cover;
  background: var(--color-surface-muted);
  display: block;
}

.user-profile-avatar-placeholder {
  background: linear-gradient(135deg, var(--color-border), var(--color-surface-muted));
}

.user-profile-banner-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
}

.user-profile-username {
  margin: 0;
  font-size: var(--font-size-h3);
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.user-profile-score {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  margin: 0;
  padding: var(--space-2xs) var(--space-sm);
  border: var(--border-width) solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tabs */

.user-profile-tabs {
  display: flex;
  gap: var(--space-lg);
  padding: 0 var(--space-xl);
  border-bottom: var(--border-width) solid var(--color-border);
}

.user-profile-tabs[hidden] {
  display: none;
}

.user-profile-tab {
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-body-small);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.user-profile-tab:hover,
.user-profile-tab.is-active {
  background: transparent;
  color: var(--color-text);
}

.user-profile-tab.is-active {
  text-decoration: underline;
  text-decoration-color: var(--color-primary-blue);
  text-decoration-thickness: 3px;
  text-underline-offset: 10px;
}

/* Panels */

.user-profile-panel[hidden] {
  display: none;
}

/* Profile panel (action buttons) */

.user-profile-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl) var(--space-lg);
  border-top: var(--border-width) solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface-muted) 45%, transparent);
}

.user-profile-actions .button {
  width: 100%;
  min-height: 54px;
  font-size: var(--font-size-body-small);
}

.user-profile-notice {
  padding: var(--space-md) var(--space-xl);
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-body-small);
  text-align: center;
}

/* Levels panel */

.user-profile-levels {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
}

.user-profile-level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-xl);
  border-top: var(--border-width) solid var(--color-border);
  color: inherit;
  text-decoration: none;
  transition: background var(--transition-fast);
}

.user-profile-levels li:first-child .user-profile-level {
  border-top: 0;
}

.user-profile-level:hover {
  background: var(--color-surface-muted);
  text-decoration: none;
}

.user-profile-level-name {
  font-size: var(--font-size-body-small);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-profile-level-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.user-profile-level-difficulty {
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-weight: var(--font-weight-bold);
  text-transform: capitalize;
}

.difficulty-easy       { background: rgba(22, 163, 74, 0.14);  color: #15803d; }
.difficulty-medium     { background: rgba(234, 179, 8, 0.18);  color: #a16207; }
.difficulty-hard,
.difficulty-impossible { background: rgba(220, 38, 38, 0.14);  color: #b91c1c; }

.user-profile-level-plays {
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Status messages */

.user-profile-loading {
  margin: var(--space-md) 0 var(--space-lg);
  color: var(--color-text-muted);
  font-size: var(--font-size-body-small);
}

.user-profile-error {
  margin: var(--space-md) 0 var(--space-lg);
  color: #b42318;
  font-size: var(--font-size-body-small);
}

.user-profile-action-error {
  margin: 0;
  padding: 0 var(--space-xl) var(--space-md);
  color: #b42318;
  font-size: var(--font-size-body-small);
  text-align: center;
}

/* Clickable usernames on the page */

.profile-trigger {
  cursor: pointer;
}

.profile-trigger:hover {
  color: var(--color-primary-blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

:root[data-theme="dark"] .user-profile-stat-value,
:root[data-theme="dark"] .profile-trigger:hover,
:root[data-theme$="-dark"] .user-profile-stat-value,
:root[data-theme$="-dark"] .profile-trigger:hover {
  color: var(--color-readable-blue, #9de4ff);
}
