/* ── PROFILE MODAL ────────────────────────── */
#profile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 18, 0.82);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding-top: 40px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#profile-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.profile-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 500px;
  max-width: 95vw;
  padding: 28px;
  transform: translateY(16px) scale(.97);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), opacity .22s ease;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
}

#profile-overlay.open .profile-modal {
  transform: translateY(0) scale(1);
}

.profile-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  position: relative;
  overflow: visible;
  cursor: pointer;
}

.profile-avatar::before {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px solid rgb(var(--accent-rgb) / 0.76);
  border-radius: 999px;
  pointer-events: none;
}

.profile-avatar::after {
  content: 'Editar';
  position: absolute;
  inset: 0;
  background: rgb(8 10 18 / 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.2s;
}

.profile-avatar:hover::after {
  opacity: 1;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  transition: filter 0.2s;
}

.profile-avatar:hover img {
  filter: blur(2px) brightness(0.7);
}

.profile-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.profile-user-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  line-height: 1.1;
  width: 100%;
  text-align: left;
}

.profile-user-name .name-val {
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.profile-user-name .name-val:hover {
  background: var(--surface2);
  cursor: pointer;
}

.profile-user-name .name-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--text);
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  padding: 2px 4px;
  border-radius: 4px;
  width: 100%;
  outline: none;
}

.profile-user-email {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  word-break: break-word;
  width: 100%;
  text-align: left;
}

.profile-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 10px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.profile-close-btn:hover {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface2) 92%, transparent);
}

.profile-edit-link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.profile-edit-link:hover {
  color: var(--text);
}

.profile-edit-link [data-lucide] {
  width: 14px;
  height: 14px;
}

/* ── SECTIONS ──────────────────────────────*/
.profile-section {
  margin-bottom: 24px;
}

.profile-section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── XP CARD ───────────────────────────────*/
.xp-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.xp-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}

.xp-level {
  color: var(--text-muted);
}

.xp-level-val {
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.xp-total {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.xp-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.xp-bar {
  flex: 1;
  height: 8px;
  background: var(--surface3);
  border-radius: 4px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #fc5c7c);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.xp-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  min-width: 30px;
  text-align: right;
}

.xp-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.xp-needed {
  font-weight: 500;
}

.xp-calc {
  font-family: var(--font-mono);
}

/* ── STATS GRID ────────────────────────────*/
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s;
}

.stat-item:hover {
  border-color: var(--accent);
  background: var(--surface3);
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.stat-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
  word-break: break-word;
}

/* ── RESPONSIVE ────────────────────────────*/
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.badge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.badge-item:hover {
  border-color: var(--accent);
  background: var(--surface3);
}

.badge-item.locked {
  opacity: 0.4;
  background: var(--surface2);
  filter: grayscale(1);
}

.badge-item.locked:hover {
  border-color: var(--border);
  background: var(--surface2);
  cursor: help;
  opacity: 0.6;
}

/* ── CUSTOM TOOLTIP ── */
.badge-item[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--support-tooltip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  padding: 7px 10px;
  border-radius: 10px;
  width: max-content;
  max-width: 180px;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 10;
  box-shadow: var(--shadow-overlay);
}

@media (hover: hover) {
  .badge-item[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-1px);
  }
}

.badge-item-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.2s;
}

.badge-item-icon [data-lucide] {
  width: 22px;
  height: 22px;
  stroke-width: 2.1;
}

.badge-item:not(.locked):hover .badge-item-icon {
  transform: scale(1.2) rotate(5deg);
}

.badge-item-name {
  font-size: 9px;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  line-height: 1.2;
}

.badge-item.locked .badge-item-name {
  color: var(--text-dim);
}

.badge-item-rarity {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 0 0 var(--radius) var(--radius);
}

.badge-item-rarity.common {
  background: #6b6b88;
}

.badge-item-rarity.rare {
  background: #5cb4fc;
}

.badge-item-rarity.epic {
  background: #6450f0;
}

.badge-item-rarity.legendary {
  background: #fc5c7c;
}

/* Borda colorida no card por raridade */
.badge-item.rare      { border-color: rgba(92, 180, 252, 0.45); }
.badge-item.epic      { border-color: rgba(100, 80, 240, 0.5); }
.badge-item.legendary {
  border-color: rgba(252, 92, 124, 0.5);
  box-shadow: 0 0 12px rgba(252, 92, 124, 0.12);
}

/* ── HISTORY ───────────────────────────────*/
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface2);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  font-size: 12px;
}

.history-type {
  flex: 1;
  color: var(--text);
  font-weight: 500;
}

.history-time {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
}

.history-points {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

.history-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 12px;
}

/* ── PROFILE BUTTON (SIDEBAR) ──────────────*/
.profile-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  margin-top: 6px;
}

.profile-btn:hover {
  border-color: var(--accent);
  color: #a090ff;
  background: var(--accent-glow);
}

/* ── XP BAR (SIDEBAR FOOTER) ───────────────*/
.xp-bar-sidebar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.xp-bar-sidebar-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
}

.xp-bar-sidebar-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.xp-bar-sidebar-fill {
  flex: 1;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  overflow: hidden;
}

.xp-bar-sidebar-progress {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #fc5c7c);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.xp-bar-sidebar-percent {
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--text-muted);
  min-width: 20px;
  text-align: right;
}

/* ── RESPONSIVE ────────────────────────────*/
@media (max-width: 600px) {
  .badges-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .profile-modal {
    width: 100%;
    padding: 20px;
  }

  .profile-header {
    flex-direction: column;
    text-align: center;
  }

  .profile-user-info {
    flex: 1;
    width: 100%;
    align-items: center;
  }
}

/* ── MOBILE RESPONSIVENESS ──────────────────────────── */
@media (max-width: 768px) {
  #profile-overlay {
    padding-top: 20px;
  }

  .profile-modal {
    width: 90vw;
    padding: 20px;
    max-width: calc(100vw - 20px);
  }

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

  .profile-avatar {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }

  .profile-user-name {
    font-size: 14px;
  }

  .profile-user-email {
    font-size: 10px;
  }

  .profile-edit-link {
    align-self: center;
  }

  .profile-section-title {
    font-size: 9px;
  }

  .xp-header {
    font-size: 12px;
  }

  .xp-level-val {
    font-size: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-item {
    padding: 10px 8px;
    gap: 4px;
  }

  .stat-value {
    font-size: 18px;
  }

  .stat-label {
    font-size: 8px;
  }

  .badges-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .badge-item {
    padding: 10px;
    gap: 4px;
  }

  .badge-item-icon {
    font-size: 24px;
  }

  .badge-item-name {
    font-size: 8px;
  }

  .history-item {
    font-size: 11px;
    padding: 8px;
  }

  .history-time {
    font-size: 9px;
  }
}

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

  .profile-avatar {
    width: 45px;
    height: 45px;
    font-size: 18px;
  }

  .stats-grid {
    gap: 6px;
  }

  .badges-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .badge-item {
    padding: 8px;
  }

  .stat-item {
    padding: 8px;
  }
}

.profile-progress-shell {
  margin-top: 0;
}

.profile-progress-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.profile-progress-label {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
}

.profile-progress-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0;
}

@media (max-width: 768px) {
  .profile-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .profile-close-btn {
    align-self: flex-end;
  }
}
