/* ============================================================
   DigitalKiddo™ Maths — My Profile Page
   ============================================================
   Builds on style.css (CSS variables, .card, .btn, .sidebar,
   .progress-bar-*). All classes are pf-* scoped to avoid clashes.
   Mobile-first; min 320px. ============================================ */

/* ── Large Text (mirrors learning.css base rule so the toggle works
      on this page without loading learning.css) ──────────────────── */
body.large-text { font-size: 18px; }

/* ============================================================
   HERO
============================================================ */
.pf-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--primary), #8b85ff 55%, var(--pink));
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.75rem;
  color: var(--white);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.pf-hero-deco {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 88% 12%, rgba(255,255,255,0.22), transparent 42%),
    radial-gradient(circle at 8% 92%, rgba(255,217,61,0.20), transparent 40%);
  pointer-events: none;
}
.pf-hero-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.pf-hero-avatar {
  flex-shrink: 0;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 3px solid rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.pf-hero-info { flex: 1; min-width: 180px; }
.pf-hero-name {
  color: var(--white);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  margin-bottom: 0.6rem;
  line-height: 1.1;
}
.pf-hero-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pf-tag {
  display: inline-flex;
  align-items: center;
  background: rgba(255,255,255,0.20);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}
.pf-tag-member { background: rgba(255,217,61,0.30); }
.pf-hero-joined {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.9;
}
.pf-hero-actions { flex-shrink: 0; }

/* ── Profile completion ─────────────────────────────────────── */
.pf-completion {
  position: relative;
  margin-top: 1.5rem;
  background: rgba(255,255,255,0.14);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
}
.pf-completion-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
}
.pf-completion-top strong { font-family: 'Fredoka One', cursive; font-size: 1.3rem; }
.pf-completion-bar {
  background: rgba(255,255,255,0.25);
  border-radius: 20px;
  height: 12px;
  overflow: hidden;
}
.pf-completion-fill {
  height: 100%;
  border-radius: 20px;
  background: linear-gradient(to right, var(--accent), var(--green));
  transition: width 1.2s cubic-bezier(0.4,0,0.2,1);
}
.pf-completion-hint {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.92;
}

/* ============================================================
   LAYOUT GRID + CARDS
============================================================ */
.pf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.pf-card { margin-bottom: 0; }
/* Cards should not lift on hover here — they hold dense content */
.pf-card:hover { transform: none; box-shadow: var(--shadow-sm); }

/* ============================================================
   AVATAR PICKER
============================================================ */
.pf-avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.75rem;
}
.pf-avatar-grid-modal { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.pf-avatar-option {
  background: var(--gray-100);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  transition: var(--transition);
  text-align: center;
}
.pf-avatar-option:hover { transform: translateY(-3px); background: rgba(108,99,255,0.08); }
.pf-avatar-option.selected {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(108,99,255,0.12), rgba(253,121,168,0.12));
  box-shadow: var(--shadow-sm);
}
.pf-avatar-emoji { font-size: 2.1rem; line-height: 1; }
.pf-avatar-name {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--gray-600);
  line-height: 1.15;
}
.pf-avatar-option.selected .pf-avatar-name { color: var(--primary); }

/* ============================================================
   LEARNING JOURNEY TIMELINE
============================================================ */
.pf-timeline { position: relative; padding-left: 0.5rem; }
.pf-timeline-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0;
}
.pf-timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 19px;
  top: 2.6rem;
  bottom: -0.6rem;
  width: 2px;
  background: var(--gray-200);
}
.pf-timeline-dot {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(108,99,255,0.12), rgba(253,121,168,0.12));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  z-index: 1;
}
.pf-timeline-body { display: flex; flex-direction: column; }
.pf-timeline-title { font-size: 0.8rem; color: var(--gray-600); font-weight: 700; }
.pf-timeline-val { font-size: 1.05rem; color: var(--dark); }

/* ============================================================
   ACHIEVEMENTS SNAPSHOT
============================================================ */
.pf-badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}
.pf-badge {
  background: linear-gradient(135deg, rgba(108,99,255,0.06), rgba(255,217,61,0.10));
  border: 1.5px solid rgba(108,99,255,0.18);
  border-radius: var(--radius-sm);
  padding: 1rem 0.5rem;
  text-align: center;
  transition: var(--transition);
}
.pf-badge:hover { transform: scale(1.05); }
.pf-badge-icon { display: block; font-size: 2rem; line-height: 1; margin-bottom: 0.35rem; }
.pf-badge-name { display: block; font-size: 0.78rem; font-weight: 800; color: var(--dark); line-height: 1.2; }
.pf-badge-tag {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--green);
}

/* ============================================================
   CURRENT MATHS RANK
============================================================ */
.profile-rank {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem;
}
.profile-rank .rank-icon {
  font-size: 3.5rem;
  line-height: 1;
}
.profile-rank .rank-name {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--primary);
  line-height: 1.15;
}
.profile-rank .rank-stars {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--dark);
  background: rgba(255,217,61,0.18);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem;
}
.profile-rank #view-ranks-btn { margin-top: 0.4rem; }

/* ============================================================
   FUN STATS
============================================================ */
.pf-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}
.pf-stat {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 1rem;
}
.pf-stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.pf-stat-info strong {
  display: block;
  font-family: 'Fredoka One', cursive;
  font-size: 1.7rem;
  line-height: 1;
}
.pf-stat-info span { font-size: 0.78rem; color: var(--gray-600); font-weight: 700; }

/* ============================================================
   RECENT ACTIVITY
============================================================ */
.pf-activity { display: flex; flex-direction: column; gap: 0.5rem; }
.pf-activity-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
}
.pf-activity-thumb { font-size: 1.6rem; flex-shrink: 0; }
.pf-activity-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pf-activity-body strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pf-activity-stars { color: var(--accent); font-size: 0.9rem; letter-spacing: 1px; }
.pf-activity-time { font-size: 0.75rem; color: var(--gray-600); font-weight: 700; white-space: nowrap; flex-shrink: 0; }

/* ============================================================
   MEMBERSHIP CARD
============================================================ */
.pf-membership {
  background: linear-gradient(135deg, #2d3436, #3d4548);
  color: var(--white);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}
.pf-membership-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.1rem; }
.pf-membership-emoji { font-size: 2.6rem; line-height: 1; }
.pf-membership-plan { font-family: 'Fredoka One', cursive; font-size: 1.4rem; color: var(--white); }
.pf-membership-badge {
  display: inline-block;
  margin-top: 0.3rem;
  background: linear-gradient(135deg, var(--accent), var(--orange));
  color: var(--dark);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 50px;
}
.pf-membership-perks { display: flex; flex-direction: column; gap: 0.6rem; }
.pf-membership-perks li {
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.95;
  padding-left: 0.25rem;
}

/* ============================================================
   ACCOUNT INFORMATION
============================================================ */
.pf-account { display: flex; flex-direction: column; }
.pf-account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1.5px solid var(--gray-100);
}
.pf-account-row:last-child { border-bottom: none; }
.pf-account-label { font-size: 0.88rem; font-weight: 700; color: var(--gray-600); }
.pf-account-val {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--dark);
  text-align: right;
  word-break: break-word;
}

/* ============================================================
   SETTINGS
============================================================ */
.pf-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1.5px solid var(--gray-100);
}
.pf-setting-row:last-child { border-bottom: none; }
.pf-setting-label strong { display: block; font-size: 0.98rem; }
.pf-setting-label small { display: block; font-size: 0.8rem; color: var(--gray-600); margin-top: 2px; }

/* Toggle switch */
.pf-switch {
  flex-shrink: 0;
  width: 52px;
  height: 30px;
  border-radius: 30px;
  background: var(--gray-200);
  position: relative;
  transition: var(--transition);
  padding: 0;
}
.pf-switch.on { background: var(--green); }
.pf-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: var(--transition);
}
.pf-switch.on .pf-switch-knob { left: 25px; }

/* ============================================================
   EMPTY STATES
============================================================ */
.pf-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1.75rem 1rem;
  color: var(--gray-600);
}
.pf-empty-emoji { font-size: 2.6rem; margin-bottom: 0.5rem; }
.pf-empty p { font-weight: 700; margin-bottom: 0.9rem; font-size: 0.92rem; }

/* ============================================================
   EDIT MODAL
============================================================ */
.pf-modal { text-align: left; }
.pf-modal h3 { color: var(--dark); }

/* ============================================================
   LARGE TEXT bumps for this page
============================================================ */
body.large-text .pf-account-label,
body.large-text .pf-setting-label small,
body.large-text .pf-stat-info span,
body.large-text .pf-timeline-title { font-size: 0.95rem; }
body.large-text .pf-badge-name,
body.large-text .pf-avatar-name { font-size: 0.85rem; }

/* ============================================================
   RESPONSIVE — single column, touch-friendly
============================================================ */
@media (max-width: 900px) {
  .pf-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .pf-hero { padding: 1.5rem 1.25rem; }
  .pf-hero-inner { gap: 1rem; }
  .pf-hero-avatar { width: 78px; height: 78px; font-size: 2.6rem; }
  .pf-hero-actions { width: 100%; }
  .pf-hero-actions .btn { width: 100%; }
  .pf-stats { grid-template-columns: 1fr 1fr; }
  .pf-avatar-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}
@media (max-width: 360px) {
  .pf-stats { grid-template-columns: 1fr; }
  .pf-avatar-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================================
   VIEW ALL RANKS — MODAL
   Self-contained (own `rank-modal-*` classes) so it never clashes with the
   global App `.modal` / `.modal-overlay` system. Reference-only popup.
============================================================ */
/* Lock background scroll while the modal is open. */
body.rank-modal-lock { overflow: hidden; }

.rank-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(45,52,54,0.7);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.rank-modal-overlay.hidden { display: none; }
.rank-modal-overlay.open { opacity: 1; pointer-events: all; }

.rank-modal-content {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 90%;          /* tablet default */
  max-width: 700px;    /* desktop cap */
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.25);
  transform: scale(0.9) translateY(16px);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
.rank-modal-overlay.open .rank-modal-content { transform: scale(1) translateY(0); }

.rank-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 2px solid var(--gray-100);
  background: linear-gradient(135deg, rgba(108,99,255,0.10), rgba(108,99,255,0.02));
  flex: 0 0 auto;
}
.rank-modal-header h3 { font-size: 1.3rem; margin: 0; color: var(--primary); }
.rank-modal-close {
  flex: 0 0 auto;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--gray-600);
  background: var(--gray-100);
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.rank-modal-close:hover { color: var(--secondary); background: rgba(255,107,107,0.12); }

.rank-modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Your Current Rank summary ─────────────────────────────── */
.rank-current-summary {
  text-align: center;
  background: rgba(108,99,255,0.06);
  border: 1.5px solid rgba(108,99,255,0.15);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.rank-current-label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--gray-600);
}
.rank-current-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
}
.rank-current-icon { font-size: 1.9rem; line-height: 1; }
.rank-current-name {
  font-family: 'Fredoka One', cursive;
  font-size: 1.35rem;
  color: var(--primary);
}
.rank-current-stars {
  display: inline-block;
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--dark);
  background: rgba(255,217,61,0.18);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.8rem;
}

/* ── Rank table ────────────────────────────────────────────── */
.rank-table-wrap {
  max-height: 52vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--gray-100);
  border-radius: var(--radius-sm);
}
.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.rank-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--primary);
  /* Match the design-system table header (.comparison-table) — Fredoka One,
     white text, subtle divider — so the modal feels native to the app. */
  font-family: 'Fredoka One', cursive;
  font-weight: 400;
  font-size: 0.95rem;
  letter-spacing: 0.3px;
  color: #fff;
  text-align: left;
  padding: 0.8rem 0.9rem;
  white-space: nowrap;
  border-bottom: 2px solid rgba(255,255,255,0.18);
}
.rank-table tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.rank-table tbody tr:last-child td { border-bottom: none; }
.rank-table tbody tr:nth-child(even) { background: var(--gray-100); }

/* Column width + alignment — shared by header and body for aligned columns. */
.rank-table .rank-col-icon  { text-align: center; width: 56px; }
.rank-table .rank-col-level { text-align: center; width: 64px; }
.rank-table .rank-col-stars { white-space: nowrap; }
/* Body-cell appearance only — never bleeds into the (uniform) header row. */
.rank-table tbody td.rank-col-icon  { font-size: 1.4rem; }
.rank-table tbody td.rank-col-level { font-weight: 800; color: var(--gray-600); }
.rank-table tbody td.rank-col-name  { font-weight: 700; color: var(--dark); }
.rank-table tbody td.rank-col-stars { font-weight: 700; color: var(--gray-600); }

/* Highlight the authenticated user's current rank (exactly one row). */
.rank-table tbody tr.current-rank,
.rank-table tbody tr.current-rank:nth-child(even) {
  background: rgba(108,99,255,0.12);
  font-weight: 800;
  box-shadow: inset 4px 0 0 var(--primary);
}
.rank-table tbody tr.current-rank .rank-col-name { color: var(--primary); }
.rank-current-tag {
  display: inline-block;
  font-family: 'Nunito', sans-serif;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--white);
  background: var(--primary);
  border-radius: 50px;
  padding: 1px 8px;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* ── Responsive: tablet 90%, mobile full-width ─────────────── */
@media (max-width: 640px) {
  .rank-modal-overlay { padding: 0; }
  .rank-modal-content {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .rank-modal-header { padding: 1rem 1.1rem; }
  .rank-modal-header h3 { font-size: 1.1rem; }
  .rank-modal-body { padding: 1rem 1.1rem 1.25rem; }
  .rank-table-wrap { max-height: none; }
  .rank-table { font-size: 0.86rem; }
  .rank-table thead th,
  .rank-table tbody td { padding: 0.6rem 0.55rem; }
  .rank-table .rank-col-icon { width: 40px; }
  .rank-table tbody td.rank-col-icon { font-size: 1.2rem; }
  .rank-table .rank-col-level { width: 46px; }
}
