/* ============================================================
   CULTURILY — PROFILE PAGE
   Extends global.css + components.css.
   Covers: loading, page shell, header, stats, culture card,
   achievement grid, edit mode, friendship buttons.
   ============================================================ */

/* ── Loading splash ─────────────────────────────────────────── */

.pf-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  background: var(--bg);
  z-index: 100;
}

/* ── Error state ────────────────────────────────────────────── */

.pf-error-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-6);
  text-align: center;
}

/* ── Page shell ─────────────────────────────────────────────── */

.pf-page {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-bottom-h) + var(--sp-6));
  max-width: var(--app-width);
  margin-inline: auto;
}

/* ── Back bar (other-user view) ─────────────────────────────── */

.pf-back-bar {
  display: flex;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.pf-back-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-subtle);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  border: none;
  background: none;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.pf-back-btn:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

/* ── Header ─────────────────────────────────────────────────── */

.pf-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-8) var(--sp-5) var(--sp-5);
  gap: var(--sp-3);
  text-align: center;
}

.pf-avatar-area {
  position: relative;
  display: inline-block;
  margin-bottom: var(--sp-1);
}

.pf-super-badge {
  position: absolute;
  bottom: -2px;
  right: -8px;
  background: var(--accent);
  color: #0e0e0e;
  font-size: 9px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: var(--r-full);
  border: 2px solid var(--bg);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.5;
}

.pf-name {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.015em;
}

.pf-country {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text-subtle);
  min-height: 22px;
}

.pf-bio {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 300px;
  line-height: var(--leading-relaxed);
  margin: 0;
}

.pf-joined {
  font-size: var(--text-xs);
  color: var(--text-subtle);
  margin: 0;
}

.pf-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Stats grid ─────────────────────────────────────────────── */

.pf-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-5);
}

.pf-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--sp-3) var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-align: center;
}

.pf-stat-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.pf-stat-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

/* ── Section wrapper ────────────────────────────────────────── */

.pf-section {
  padding: 0 var(--sp-4) var(--sp-6);
}

.pf-section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin: 0 0 var(--sp-3);
}

/* ── Culture card ───────────────────────────────────────────── */

.pf-culture-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid #4A9EFF;
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}

.pf-culture-top {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.pf-culture-flag {
  font-size: 30px;
  line-height: 1;
  flex-shrink: 0;
}

.pf-culture-meta {
  flex: 1;
  min-width: 0;
}

.pf-culture-name {
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--text-primary);
  margin: 0 0 2px;
}

.pf-culture-level-title {
  font-size: var(--text-sm);
  color: var(--text-subtle);
  margin: 0;
}

.pf-culture-level-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
}

.pf-culture-level-num {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.pf-culture-level-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.pf-culture-xp-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  margin-bottom: var(--sp-1);
}

.pf-culture-xp-curr {
  color: var(--accent);
  font-weight: 700;
}

.pf-culture-streak {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-sm);
  font-weight: 700;
  color: #ff8c42;
  margin-top: var(--sp-3);
}

.pf-culture-no-data {
  font-size: var(--text-sm);
  color: var(--text-subtle);
  text-align: center;
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* ── Achievements grid ──────────────────────────────────────── */

.pf-achievements-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}

/* ── Edit mode: inline inputs ───────────────────────────────── */

.pf-edit-field {
  width: 100%;
  max-width: 300px;
}

.pf-edit-input {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  text-align: center;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.pf-edit-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.pf-edit-input.input-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px var(--error-dim);
}

.pf-edit-error {
  font-size: var(--text-xs);
  color: var(--error);
  text-align: center;
  margin-top: 4px;
}

.pf-edit-textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  text-align: center;
  resize: none;
  min-height: 72px;
  line-height: var(--leading-relaxed);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.pf-edit-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.pf-country-select {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  text-align: center;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgba(248,248,248,0.45)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: var(--sp-8);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.pf-country-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.pf-country-select option {
  background: var(--surface-3);
  color: var(--text-primary);
}

/* ── Avatar colour picker ───────────────────────────────────── */

.pf-avatar-color-picker {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-1) 0;
}

.pf-color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  flex-shrink: 0;
}

.pf-color-swatch:hover { transform: scale(1.08); }

.pf-color-swatch.is-selected {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

/* ── Fixed save / cancel bar (edit mode) ───────────────────── */

.pf-edit-bar {
  position: fixed;
  bottom: var(--nav-bottom-h);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-width);
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  gap: var(--sp-2);
  z-index: calc(var(--z-sticky) + 1);
  animation: slideUp var(--t-base) var(--ease-out) both;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(100%); }
  to   { transform: translateX(-50%) translateY(0); }
}

/* ── Sign out section ───────────────────────────────────────── */

.pf-signout-section {
  padding: 0 var(--sp-4) var(--sp-4);
}

/* ── Toast ──────────────────────────────────────────────────── */

.pf-toast {
  position: fixed;
  top: var(--sp-5);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}

.pf-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 380px) {
  .pf-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
