/* ============================================================
   OrzuTalim — PROFILE STYLES (mobile-first)
   Avatar real photo + skeleton fallback, mastery bars,
   achievement chips, customization preview, crop modal.
   Mobile: 320-430px qamrov, 44px+ touch targetlar.
   ============================================================ */

/* ---------- Topbar / dropdown avatar photo qo'llab-quvvatlashi ---------- */
.user-avatar,
#ndHeroAvatar {
  position: relative;
  overflow: hidden;
}

.user-avatar img,
#ndHeroAvatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ---------- PROFIL HEADER ---------- */
.pf-head {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 28px 16px 24px;
  margin-bottom: 16px;
}

.pf-avatar {
  position: relative;
  width: var(--pf-av, 96px);
  height: var(--pf-av, 96px);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary, #5b7cfa), var(--secondary, #8b5cf6));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 30px rgba(91, 124, 250, 0.3);
  flex: 0 0 auto;
}

.pf-avatar-fallback {
  font-size: calc(var(--pf-av, 96px) * 0.42);
  line-height: 1;
  color: #fff;
  user-select: none;
}

.pf-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 2;
}

.pf-avatar-img.loaded {
  opacity: 1;
}

.pf-avatar-xl { --pf-av: clamp(104px, 28vw, 136px); }
.pf-avatar-lg { --pf-av: 84px; }
.pf-avatar-sm { --pf-av: 56px; }
.pf-avatar-xs { --pf-av: 34px; }

/* ---------- STICKY PROFILE BAR (scroll paytida ixcham header) ----------
   - .pf-sticky: `position: sticky` shell, balandligi 0 → oqimda joy egallamaydi
     (hero card ham, boshqa kartalar ham surilmaydi / ustma-ust tushmaydi)
   - .pf-sticky-bar: abs ichki bar — shell bilan birga yopishadi
   - top: real topbar balandligi (JS --pf-sticky-top ni o'lchab qo'yadi)
   - z-index: 60 → desktop topbar(90)/sidebar(100) va mobil topbar(80) OSTIDA
   - fon: opaque (blur faqat qo'shimcha effekt) */
.pf-sticky {
  position: sticky;
  top: var(--pf-sticky-top, 64px);
  height: 0;
  margin: 0;
  z-index: 60;
  pointer-events: none;
}

.pf-sticky-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  box-sizing: border-box;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 7px 12px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-sm, 12px);
  background: var(--bg, #070a13); /* opaque fallback (color-mix yo'q brauzerlar) */
  background: color-mix(in srgb, var(--bg, #070a13) 93%, var(--primary, #6366f1));
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-14px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.26s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.26s linear;
}

.pf-sticky.is-stuck .pf-sticky-bar {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.pf-sticky-id {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 4px 0 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.pf-sticky-id:active { transform: scale(0.99); }

.pf-sticky-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.18;
}

.pf-sticky-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.pf-sticky-user {
  font-size: 12px;
  color: var(--muted, #94a3b8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.pf-sticky-edit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  font-size: 13.5px;
  white-space: nowrap;
}


.pf-cam {
  position: relative;
  margin-top: -18px;
  margin-left: 96px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--card, #fff);
  background: var(--primary, #5b7cfa);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s var(--bounce, ease);
}

.pf-cam:hover { transform: scale(1.08); }
.pf-cam:active { transform: scale(0.95); }

.pf-name {
  margin: 14px 0 2px;
  font-size: clamp(19px, 5vw, 24px);
  font-weight: 700;
  word-break: break-word;
}

.pf-username {
  color: var(--muted, #9ca3af);
  font-size: 14px;
}
.pf-bio {
  margin: 10px 0 0;
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 420px;
  word-break: break-word;
}

.pf-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  font-size: 12.5px;
  margin-top: 8px;
  word-break: break-all;
}

.pf-actions {
  margin-top: 16px;
  width: 100%;
  max-width: 320px;
}

.pf-actions .btn {
  width: 100%;
  min-height: 46px;
}

/* ---------- KARTALAR ---------- */
.pf-card {
  margin-bottom: 16px;
}

.pf-card .card-header h3 {
  margin: 0;
}

.pf-details-btn {
  margin-top: 12px;
  min-height: 44px;
}

/* Mastery */
.pf-mastery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  min-width: 0;
}

.pf-mastery-name {
  flex: 0 0 92px;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pf-bar {
  flex: 1 1 auto;
  display: flex;
  gap: 3px;
  min-width: 0;
}

.pf-bar-seg {
  flex: 1 1 0;
  height: 10px;
  border-radius: 3px;
  background: var(--border, rgba(255, 255, 255, 0.12));
  transition: background 0.3s ease;
}

.pf-bar-seg.on {
  background: linear-gradient(90deg, var(--primary, #5b7cfa), var(--secondary, #8b5cf6));
}

.pf-bar-pct {
  flex: 0 0 42px;
  text-align: right;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.pf-mastery-attempts {
  flex: 0 0 auto;
  font-size: 11.5px;
}
/* Achievements */
.pf-ach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pf-ach {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: var(--bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
}

.pf-ach.locked {
  opacity: 0.45;
  filter: grayscale(0.6);
}

.pf-ach-note {
  margin-top: 10px;
  font-size: 12.5px;
}

/* Customization preview */
.pf-cust-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.pf-cust-preview .store-equipped {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

/* ---------- EDIT MODAL — avatar bloki ---------- */
.pf-edit-avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.pf-edit-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 300px;
}

.pf-edit-avatar-actions .btn {
  min-height: 44px;
  width: 100%;
}
/* ---------- CROP MODAL ---------- */
.modal.pf-crop-modal {
  width: min(92vw, 440px) !important;
  max-width: min(92vw, 440px) !important;
  max-height: calc(100vh - 32px) !important;
  margin: auto !important;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  padding: 0 !important;
  border-radius: 18px !important;
}

.pf-crop-modal .modal-header {
  flex: 0 0 auto;
  padding: 14px 18px;
}

.pf-crop-modal .modal-header h3 {
  font-size: 16px;
  margin: 0;
}

.pf-crop-modal .modal-body {
  flex: 1 1 auto;
  overflow: hidden !important;
  padding: 4px 18px 8px !important;
}

.pf-crop-modal .modal-footer {
  flex: 0 0 auto;
  padding: 10px 18px 18px !important;
  gap: 10px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}

.pf-crop-modal .modal-footer .btn {
  min-height: 44px;
}

.pf-crop-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(62vh, 420px);
  border-radius: 16px;
  overflow: hidden;
  background: #070a13;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}

.pf-crop-stage:active { cursor: grabbing; }

#pfCropImg {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  max-width: none;
  max-height: none;
  will-change: transform;
  pointer-events: none;
  display: block;
  -webkit-user-drag: none;
}

.pf-crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(4, 6, 16, 0.55);
  border-radius: 16px;
}

.pf-crop-frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(255, 255, 255, 0.12);
}

.pf-crop-frame::before,
.pf-crop-frame::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.35);
}

.pf-crop-frame::before {
  top: 33.333%;
  bottom: 33.333%;
  left: 0;
  right: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
}

.pf-crop-frame::after {
  left: 33.333%;
  right: 33.333%;
  top: 0;
  bottom: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.28);
  border-right: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
}

.pf-crop-hint {
  margin: 12px 0 2px;
  font-size: 12.5px;
  color: var(--muted, #9ca3af);
  text-align: center;
  line-height: 1.4;
}

/* ---------- MOBILE (≤640px) ---------- */
@media (max-width: 640px) {
  .pf-head {
    padding: 22px 12px 20px;
  }

  /* Sticky bar — mobil uchun ixcham (ekran maydonini ko'p egallamaydi) */
  .pf-sticky-bar {
    min-height: 52px;
    padding: 6px 10px;
    gap: 8px;
    border-radius: 12px;
  }

  .pf-sticky-id {
    gap: 8px;
  }

  .pf-sticky-name {
    font-size: 14px;
  }

  .pf-sticky-user {
    font-size: 11.5px;
  }

  .pf-sticky-edit {
    min-height: 38px;
    padding: 0 11px;
    gap: 5px;
    font-size: 12.5px;
  }

  .pf-cam {
    margin-left: 76px;
    width: 42px;
    height: 42px;
  }

  .pf-mastery-name {
    flex-basis: 78px;
    font-size: 12.5px;
  }

  .pf-ach {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }
}
/* ---------- KICHIK MOBIL (≤360px) ---------- */
@media (max-width: 360px) {
  /* 320–360px: joy tejash — tahrirlash tugmasi ikonka ko'rinishida
     (aria-label saqlanadi, touch target 38px) */
  .pf-sticky-edit-txt {
    display: none;
  }

  .pf-sticky-edit {
    padding: 0 13px;
    font-size: 15px;
  }

  .pf-sticky-name {
    font-size: 13.5px;
  }

  .pf-sticky-user {
    font-size: 11px;
  }

  .pf-mastery-name {
    flex-basis: 66px;
    font-size: 11.5px;
  }

  .pf-bar-pct {
    flex-basis: 38px;
  }

  .pf-actions .btn,
  .pf-edit-avatar-actions .btn,
  .pf-details-btn {
    font-size: 13.5px;
  }

  .pf-cam {
    margin-left: 64px;
    width: 40px;
    height: 40px;
  }
}

/* ---------- DESKTOP (≥900px): keng 2 kolonka layout ---------- */
@media (min-width: 900px) {
  #profileRoot {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 16px;
    align-items: start;
  }

  .pf-head {
    grid-column: 1 / -1;
    padding: 36px 32px 30px;
  }

  .pf-card {
    margin-bottom: 0;
  }
}
