:root {
  color-scheme: light;
  --ink: #1d3029;
  --muted: #738079;
  --paper: #f7f8f5;
  --white: #fff;
  --green: #176b52;
  --green-dark: #104c3c;
  --green-pale: #e6f1eb;
  --green-soft: #eaf4ee;
  --line: #e2e8e1;
  --line-light: #edf2ec;
  --gold: #dfaa42;
  --gold-dark: #b88628;
  --gold-pale: #fdf5e6;
  --orange: #e06d28;
  --orange-pale: #fcf1e8;
  --red: #b9382e;
  --shadow-sm: 0 2px 8px rgba(23,62,43,.04);
  --shadow-md: 0 8px 24px rgba(23,62,43,.07);
  --shadow-lg: 0 16px 44px rgba(23,62,43,.09);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { min-width: 320px; margin: 0; color: var(--ink); background: var(--paper); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.wrap { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }

/* Barra superior */
.topbar {
  position: sticky; z-index: 20; top: 0; height: 68px;
  border-bottom: 1px solid rgba(225,231,224,.85);
  background: rgba(247,248,245,.92); backdrop-filter: blur(16px);
}
.nav { display: flex; align-items: center; justify-content: space-between; height: 100%; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand img { width: 34px; height: 45px; object-fit: contain; }
.brand-copy { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 17px; font-weight: 850; letter-spacing: 1.1px; }
.brand-tagline { color: var(--muted); font-size: 8px; white-space: nowrap; }

.nav-actions { display: flex; align-items: center; gap: 10px; }
.nav-link {
  padding: 8px 14px; border-radius: 99px; color: #526159;
  font-size: 12px; font-weight: 700; transition: .2s;
}
.nav-link:hover { background: var(--green-pale); color: var(--green-dark); }
.nav-link.active { background: var(--green-pale); color: var(--green-dark); }
.nav-link.logout { border: 1px solid var(--line); background: var(--white); cursor: pointer; }

/* Contenedor principal */
main { padding: 32px 0 70px; }

/* Estado de carga inicial */
.profile-gate {
  padding: 60px 24px; text-align: center; border-radius: 20px;
  border: 1px solid var(--line); background: var(--white);
  box-shadow: var(--shadow-sm); max-width: 520px; margin: 40px auto;
}
.profile-gate h2 { margin: 0 0 10px; font-size: 20px; }
.profile-gate p { margin: 0; color: var(--muted); font-size: 13px; }

/* Tarjeta Hero del Perfil */
.profile-hero {
  position: relative; overflow: hidden; padding: 32px;
  border: 1px solid var(--line); border-radius: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f6faf5 100%);
  box-shadow: var(--shadow-md); margin-bottom: 24px;
}
.profile-hero::after {
  position: absolute; right: -40px; top: -40px; width: 220px; height: 220px;
  border-radius: 50%; background: radial-gradient(circle, rgba(23,107,82,.08), transparent 70%);
  pointer-events: none; content: "";
}
.hero-layout { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }

/* Avatar */
.avatar-wrap {
  position: relative; width: 96px; height: 96px; flex-shrink: 0;
}
.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
  border: 3px solid var(--white); box-shadow: 0 6px 18px rgba(23,62,43,.15);
  background: #d8e8dc;
}
.avatar-fallback {
  width: 100%; height: 100%; display: grid; place-items: center;
  border-radius: 50%; background: linear-gradient(135deg, #d8e8dc, #b8d6bf);
  color: var(--green-dark); font-size: 32px; font-weight: 800;
  border: 3px solid var(--white); box-shadow: 0 6px 18px rgba(23,62,43,.15);
}
.avatar-badge-level {
  position: absolute; bottom: -2px; right: -2px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--gold); color: var(--white);
  display: grid; place-items: center; font-size: 11px; font-weight: 850;
  border: 2px solid var(--white); box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

.hero-info { flex: 1; min-width: 240px; }
.hero-tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 99px; background: var(--green-pale); color: var(--green-dark);
  font-size: 10px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
}
.hero-name { margin: 8px 0 4px; font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.hero-email { margin: 0; color: var(--muted); font-size: 13px; }
.hero-meta { display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.meta-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  color: #4f6056; font-weight: 600;
}

/* Grilla de Gamificación (Racha, Nivel, Progreso) */
.gamification-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.stat-card {
  padding: 20px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--white); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 12px; transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-card-icon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-size: 20px;
}
.icon-fire { background: var(--orange-pale); color: var(--orange); }
.icon-star { background: var(--gold-pale); color: var(--gold-dark); }
.icon-book { background: var(--green-soft); color: var(--green-dark); }
.icon-trophy { background: #f2eef8; color: #6f42c1; }

.stat-label { font-size: 11px; font-weight: 750; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat-value { font-size: 24px; font-weight: 850; color: var(--ink); line-height: 1.1; }
.stat-subtext { font-size: 11px; color: var(--muted); }

/* Barra de progreso de nivel */
.xp-bar-wrap { width: 100%; height: 7px; background: #eaf0ea; border-radius: 99px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--gold), #f5c45b); border-radius: 99px; transition: width .4s ease; }

/* Contenedor del Formulario */
.profile-card {
  padding: 34px; border: 1px solid var(--line); border-radius: 24px;
  background: var(--white); box-shadow: var(--shadow-md);
}
.section-title { margin: 0 0 6px; font-size: 21px; font-weight: 800; letter-spacing: -.4px; }
.section-desc { margin: 0 0 24px; color: var(--muted); font-size: 13px; }

.form-fieldset {
  margin: 0 0 32px; padding: 22px; border: 1px solid var(--line-light);
  border-radius: 18px; background: #fafbfa;
}
.fieldset-legend {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  font-weight: 800; color: var(--green-dark); margin-bottom: 16px;
}
.fieldset-legend svg, .fieldset-legend span { font-size: 16px; }

.form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 14px;
}
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }

label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 700; color: #3d4a43; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--white); color: var(--ink); font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23,107,82,.14);
}
input[readonly] { background: #f3f5f3; cursor: not-allowed; color: #738079; }
textarea { min-height: 84px; padding: 10px 13px; resize: vertical; }

.field-hint { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }

/* Quick actions avatar */
.avatar-input-group { display: flex; gap: 8px; align-items: stretch; }
.avatar-input-group input { flex: 1; }
.quick-btn {
  padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--white); color: var(--green-dark); font-size: 11px;
  font-weight: 750; cursor: pointer; white-space: nowrap; transition: .15s;
}
.quick-btn:hover { background: var(--green-pale); border-color: #b8d4c2; }

/* Acciones del formulario */
.form-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line-light);
}
.btn-submit {
  min-height: 46px; padding: 0 28px; border: 0; border-radius: 99px;
  background: var(--green); color: var(--white); font-size: 13px;
  font-weight: 750; cursor: pointer; transition: background .15s, transform .1s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-submit:hover { background: var(--green-dark); }
.btn-submit:disabled { opacity: .65; cursor: wait; }

/* Mensajes de estado */
.status-toast {
  padding: 12px 16px; border-radius: 12px; font-size: 13px; font-weight: 600;
  margin-top: 16px; display: flex; align-items: center; gap: 9px;
}
.status-toast.success { background: #e7f7ed; color: #166438; border: 1px solid #b7e8c7; }
.status-toast.error { background: #fdeeee; color: var(--red); border: 1px solid #f9c9c6; }

@media (max-width: 720px) {
  .wrap { width: min(100% - 32px, 540px); }
  .profile-hero { padding: 22px; }
  .hero-layout { gap: 16px; }
  .avatar-wrap { width: 76px; height: 76px; }
  .hero-name { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .profile-card { padding: 20px; }
  .form-fieldset { padding: 16px; }
  .avatar-input-group { flex-direction: column; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .btn-submit { width: 100%; justify-content: center; }
}
