/*
 * Aprentix · cabecera unificada (Solarpunk).
 *
 * Estilo de cabecera de la aplicación remodelada de estudio.
 *
 * Móvil (< 900 px): topbar reducida con avatar a la derecha + bottom-nav
 * fijado en la parte inferior. Sheets deslizantes para el usuario y para
 * las opciones "Más".
 * Desktop (>= 900 px): topbar completa + navegación por pestañas; el
 * bottom-nav se oculta.
 */

aprentix-header { display: contents; }

/* View Transitions API para suavizar las navegaciones de la SPA. */
@view-transition { navigation: auto; }
.topbar     { view-transition-name: aprentix-topbar; }
.bottom-nav { view-transition-name: aprentix-bottomnav; }
/* Cross-fade suave y gradual. El contenido central
 * (root) hace fade-out/in encabalgado; la topbar y la bottom-nav son
 * elementos persistentes que morfan de estilo, así que llevan una
 * duración un poco más corta y la misma curva para que todo el conjunto
 * se sienta coherente. Respetamos prefers-reduced-motion. */
::view-transition-group(root) {
  animation-duration: 420ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
::view-transition-old(root) {
  animation: apx-fade-out 420ms cubic-bezier(0.4, 0, 0.2, 1) both;
}
::view-transition-new(root) {
  animation: apx-fade-in 420ms cubic-bezier(0.4, 0, 0.2, 1) both;
}
::view-transition-group(aprentix-topbar),
::view-transition-group(aprentix-bottomnav) {
  animation-duration: 320ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes apx-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes apx-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root),
  ::view-transition-old(root),
  ::view-transition-new(root),
  ::view-transition-group(aprentix-topbar),
  ::view-transition-group(aprentix-bottomnav) { animation-duration: 0.01ms; }
}

.topbar {
  display: flex; align-items: center; gap: 0.65rem;
  height: var(--topbar-h);
  padding: 0 0.75rem;
  /* En PWA instalada respetamos el notch/safe-area para que la barra no
     quede debajo del status bar del sistema. */
  padding-top: env(safe-area-inset-top, 0);
  box-sizing: content-box;
  background: var(--glass-bg);
  background-image:
    linear-gradient(90deg, var(--accent-soft) 0%, transparent 30%, transparent 70%, var(--sky-soft) 100%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
  position: sticky; top: 0;
  z-index: 30;
  color: var(--txt);
}
[data-theme="dark"] .topbar {
  background-image:
    linear-gradient(90deg, var(--pri-soft) 0%, transparent 30%, transparent 70%, var(--lavender-soft) 100%);
}
@media (min-width: 900px) {
  .topbar { padding: 0 1.75rem; gap: 1.35rem; }
}

/* Marca destacada: chip con toque solar + logo grande. */
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--pri-d);
  text-decoration: none;
  font-weight: 800; font-size: 1.1rem;
  padding: 5px 12px 5px 8px; border-radius: 999px;
  background:
    linear-gradient(120deg, var(--accent-soft) 0%, var(--pri-soft) 60%, var(--sky-soft) 100%);
  border: 1px solid var(--glass-border);
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 10px rgba(244, 183, 64, 0.15);
}
.brand:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(244, 183, 64, 0.25);
}
[data-theme="dark"] .brand {
  color: var(--pri);
  background:
    linear-gradient(120deg, var(--pri-soft) 0%, var(--lavender-soft) 60%, var(--accent-soft) 100%);
  box-shadow: 0 2px 12px rgba(92, 229, 213, 0.20);
}
[data-theme="dark"] .brand:hover {
  box-shadow: 0 4px 16px rgba(176, 132, 245, 0.30);
}
.brand .brand-logo { width: 30px; height: 30px; }
.brand-name {
  letter-spacing: 0.4px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* En móvil solo pintamos el logo para ganar espacio; el texto asoma
     a partir de 640 px. */
  display: none;
}
@media (min-width: 640px) {
  .brand { font-size: 1.25rem; padding: 6px 16px 6px 10px; }
  .brand .brand-logo { width: 34px; height: 34px; }
  .brand-name { display: inline; }
}

/* Navegación de pestañas (Tests | Teoría) — solo desktop; en móvil vive
 * dentro del sheet del avatar como switch. */
.hdr-nav {
  display: none; align-items: center; gap: 4px;
  background: var(--bg-soft);
  padding: 5px; border-radius: 999px;
  border: 1px solid var(--border);
}
.nav-tab {
  padding: 8px 18px; border-radius: 999px;
  font-size: 0.95rem; font-weight: 600;
  color: var(--txt-soft);
  cursor: pointer; user-select: none;
  text-decoration: none;
  transition: background 0.18s, color 0.18s;
  min-height: 40px;
  display: inline-flex; align-items: center;
}
.nav-tab:hover:not(.active) { color: var(--txt); background: var(--pri-soft); }
.nav-tab.active {
  background: var(--pri); color: #fff;
  cursor: default; pointer-events: none;
  box-shadow: 0 2px 8px rgba(107, 142, 35, 0.30);
}
[data-theme="dark"] .nav-tab.active {
  color: #14241D;
  box-shadow: 0 2px 12px rgba(92, 229, 213, 0.35);
}
@media (min-width: 900px) { .hdr-nav { display: inline-flex; } }

.hdr-spacer { flex: 1; min-width: 0; }

/* Chip del usuario — en móvil solo es el círculo con la inicial. */
.user-chip {
  display: flex; align-items: center; gap: 0.45rem;
  min-width: 0;
  margin-left: auto;
}
.user-btn {
  display: inline-flex; align-items: center; gap: 0.55rem;
  background: transparent; border: 0; padding: 4px 10px 4px 4px;
  border-radius: 999px; cursor: pointer; color: var(--txt);
  transition: background 0.15s;
  font: inherit;
}
.user-btn:hover { background: var(--pri-soft); }
.user-chip .avatar {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #fff; font-weight: 800;
  border-radius: 50%; font-size: 1.05rem;
  user-select: none; flex: 0 0 auto;
  box-shadow: 0 2px 6px rgba(107, 142, 35, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.4);
}
[data-theme="dark"] .user-chip .avatar {
  color: #14241D;
  box-shadow: 0 2px 10px rgba(92, 229, 213, 0.30);
  border-color: rgba(0, 0, 0, 0.25);
}
.user-chip .user-name {
  font-weight: 600; max-width: 90px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: none;
  font-size: 0.95rem;
}
@media (min-width: 900px) {
  .user-chip .user-name { display: inline; max-width: 180px; }
}

/* Botones legados (sidebar antiguo). Se dejan aquí para compatibilidad
 * con estilos internos; ya no viven en la cabecera. */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--bg-soft); color: var(--txt);
  border: 1px solid var(--border); border-radius: 50%;
  cursor: pointer; padding: 0;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.btn-icon:hover { background: var(--pri-soft); color: var(--pri-d); border-color: var(--pri); }
.btn-icon.danger-icon:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-icon:active { transform: scale(0.92); }

/* Hamburguesa antigua: por compatibilidad, si algún app la sigue
 * inyectando, la ocultamos. */
.hamburger { display: none !important; }


/* ═════════════════════════════════════════════════════════════════════
 * Bottom navigation (móvil)
 * Fijada abajo con backdrop translúcido y safe-area para gestos iOS.
 * Se oculta a partir de 900 px (desktop usa la topbar completa).
 * ═════════════════════════════════════════════════════════════════════ */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0));
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .bottom-nav {
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.35);
}
.bnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: transparent; border: 0;
  color: var(--txt-soft);
  padding: 6px 4px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 11px; font-weight: 600;
  text-decoration: none;
  min-height: 52px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, transform 0.1s;
}
.bnav-item:active { transform: scale(0.94); }
.bnav-ico {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
}
.bnav-ico svg { width: 100%; height: 100%; }
.bnav-label {
  line-height: 1;
  letter-spacing: 0.02em;
}
.bnav-item:hover { color: var(--txt); background: var(--pri-soft); }
.bnav-item.active {
  color: var(--pri-d);
  background: var(--pri-soft);
}
[data-theme="dark"] .bnav-item.active { color: var(--pri); }
.bnav-item.active .bnav-ico {
  transform: translateY(-1px);
  filter: drop-shadow(0 2px 4px rgba(107, 142, 35, 0.35));
}

/* Item especial (para admin/gestión con estilo llamativo). */
.bnav-item.special {
  color: var(--accent-d);
}
.bnav-item.special::before {
  content: ""; position: absolute; top: 4px; right: calc(50% - 14px);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}
.bnav-item { position: relative; }

/* En escritorio la misma navegación móvil se convierte en menú lateral. */
@media (min-width: 900px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
    bottom: 0;
    left: 0;
    width: 224px;
    height: auto;
    padding: 1.25rem .8rem;
    flex-direction: column;
    justify-content: flex-start;
    gap: .45rem;
    border-top: 0;
    border-right: 1px solid var(--glass-border);
    box-shadow: 8px 0 28px rgba(0, 0, 0, .05);
  }
  .bottom-nav .bnav-item {
    width: 100%;
    min-height: 50px;
    padding: .7rem .9rem;
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: .8rem;
    border-radius: 12px;
  }
  .bottom-nav .bnav-ico { width: 23px; height: 23px; }
  .bottom-nav .bnav-label { font-size: .95rem; }
}
/* Deja hueco al contenido para que la bottom-nav no tape lo último.
 * Los apps pueden anular con --bottom-nav-h si lo necesitan. */
:root {
  --bottom-nav-h: calc(58px + env(safe-area-inset-bottom, 0));
}
@media (max-width: 899.98px) {
  body {
    padding-bottom: var(--bottom-nav-h);
  }
}


/* ═════════════════════════════════════════════════════════════════════
 * Aprentix Sheet — panel deslizante que aloja el menú del usuario y
 * el sheet secundario "Más". En móvil sube desde abajo; en desktop
 * aparece como popover ancorado.
 * ═════════════════════════════════════════════════════════════════════ */
.aprentix-sheet {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.aprentix-sheet.hidden { display: none; }
.aprentix-sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.42);
  animation: sheet-fade 0.18s ease both;
}
.aprentix-sheet-card {
  position: relative;
  width: min(560px, 100%);
  background: var(--bg-panel);
  color: var(--txt);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.35);
  animation: sheet-up 0.24s cubic-bezier(0.2, 0.85, 0.35, 1.05) both;
  max-height: 80vh; overflow-y: auto;
}
.aprentix-sheet-card::before {
  content: "";
  display: block;
  width: 44px; height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 6px auto 12px;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes sheet-fade {
  from { opacity: 0; } to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .aprentix-sheet-card, .aprentix-sheet-backdrop { animation: none; }
}

/* En desktop el sheet aparece como popover a la derecha del avatar. */
@media (min-width: 900px) {
  .aprentix-sheet { align-items: flex-start; justify-content: flex-end; }
  .aprentix-sheet-backdrop { background: transparent; }
  .aprentix-sheet-card {
    width: 360px;
    margin: calc(var(--topbar-h) + 8px) 16px 0 0;
    border-radius: 16px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
    max-height: 80vh;
    animation: sheet-pop 0.18s ease both;
  }
  .aprentix-sheet-card::before { display: none; }
}
@keyframes sheet-pop {
  from { transform: translateY(-6px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.sheet-avatar {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #fff; font-weight: 800;
  border-radius: 50%; font-size: 1.15rem;
  flex: 0 0 auto;
}
[data-theme="dark"] .sheet-avatar { color: #14241D; }
.sheet-head-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sheet-head-txt strong {
  font-size: 1.05rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-mode-label {
  font-size: 0.82rem;
  color: var(--txt-soft);
}
.sheet-roles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.sheet-role {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--pri-soft);
  color: var(--pri-d);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
}
.sheet-close {
  background: transparent; border: 0;
  font-size: 1.2rem; color: var(--txt-soft);
  padding: 6px 10px; border-radius: 10px;
  cursor: pointer;
}
.sheet-close:hover { background: var(--bg-soft); color: var(--txt); }

.sheet-section { margin-top: 6px; padding: 4px 0; }
.sheet-section + .sheet-section {
  border-top: 1px solid var(--border);
  margin-top: 12px; padding-top: 12px;
}
.sheet-section-title {
  font-size: 11px; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--txt-soft);
  margin: 0 4px 8px;
}

/* Switch de "Modo" (Tests / Teoría) */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-soft);
  padding: 5px;
  border-radius: 14px;
}
.mode-opt {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--txt-soft);
  text-decoration: none;
  font-weight: 600; font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
  min-height: 42px;
}
.mode-opt:hover:not(.active) { color: var(--txt); background: var(--pri-soft); }
.mode-opt .mode-ico {
  width: 20px; height: 20px;
  display: inline-flex; align-items: center;
}
.mode-opt .mode-ico svg { width: 100%; height: 100%; }
.mode-opt.active {
  background: var(--pri); color: #fff;
  box-shadow: 0 2px 8px rgba(107, 142, 35, 0.25);
  cursor: default; pointer-events: none;
}
[data-theme="dark"] .mode-opt.active { color: #14241D; }

/* Filas del sheet: config, logout. */
.sheet-row {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0;
  color: var(--txt);
  padding: 12px 8px;
  border-radius: 12px;
  font-family: inherit; font-size: 0.98rem; font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.sheet-row:hover { background: var(--pri-soft); color: var(--pri-d); }
.sheet-row.danger { color: var(--danger); }
.sheet-row.danger:hover { background: var(--danger-soft); }
.sheet-row-ico {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: currentColor;
}
.sheet-row-ico svg { width: 100%; height: 100%; }
[data-theme="dark"] .sheet-row:hover { color: var(--pri); }

/* Lista de opciones "Más" */
.more-list {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.more-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 8px;
  color: var(--txt);
  text-decoration: none;
  font-family: inherit; font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  min-height: 78px;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.more-item:active { transform: scale(0.96); }
.more-item:hover { background: var(--pri-soft); border-color: var(--pri); color: var(--pri-d); }
.more-ico {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--pri);
}
.more-ico svg { width: 100%; height: 100%; }
[data-theme="dark"] .more-ico { color: var(--pri); }

/* Items de gestión / admin: destacados con acento coral y ámbar. */
.more-item.gestion {
  background: linear-gradient(135deg, var(--accent-soft), var(--pri-soft));
  border-color: var(--accent);
  color: var(--accent-d);
}
.more-item.gestion .more-ico { color: var(--accent-d); }
.more-item.solo-admin {
  background: linear-gradient(135deg, var(--coral-soft, #ffe0dc), var(--accent-soft));
  border-color: var(--coral, #ea7a63);
  color: var(--coral-d, #b0432b);
  position: relative;
}
.more-item.solo-admin::after {
  content: "ADMIN";
  position: absolute; top: 6px; right: 6px;
  font-size: 8px; font-weight: 900; letter-spacing: 0.12em;
  padding: 2px 5px;
  background: var(--coral, #ea7a63);
  color: #fff;
  border-radius: 999px;
}
.more-item.solo-admin .more-ico { color: var(--coral-d, #b0432b); }

/* Oculta más-items para los que no tienen permiso. Los apps pintan
 * body.puede-gestionar / body.es-admin al aplicar la sesión. */
body:not(.puede-gestionar) .more-item.gestion,
body:not(.puede-gestionar) .bnav-item.gestion { display: none; }
body:not(.es-admin) .more-item.solo-admin,
body:not(.es-admin) .bnav-item.solo-admin { display: none; }

/* Fila "Cambiar oposición": solo cuando el usuario tiene más de una
 * accesible (body.has-oposiciones). El hint muestra la actual a la derecha. */
body:not(.has-oposiciones) .sheet-row.sheet-oposicion { display: none; }
.sheet-row-hint {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--txt-soft);
  max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Fila "Panel de admin" en el sheet del usuario: destacada con acento
 * cálido para diferenciarla del resto y aviso ADMIN a la derecha.
 * Se oculta si el usuario no es gestor ni admin. */
body:not(.puede-gestionar):not(.es-admin) .sheet-row.admin-row {
  display: none;
}
.sheet-row.admin-row {
  background: linear-gradient(90deg, var(--accent-soft), var(--pri-soft));
  border: 1.5px dashed var(--accent);
  color: var(--accent-d);
  margin: 4px 0;
  font-weight: 700;
}
.sheet-row.admin-row:hover {
  background: linear-gradient(90deg, var(--accent-soft), var(--coral-soft, #ffe0dc));
  color: var(--accent-d);
  border-color: var(--coral, #ea7a63);
}
.sheet-row.admin-row .sheet-row-ico { color: var(--accent-d); }
.sheet-row-badge {
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--coral, #ea7a63);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

/* Sheet de admin: mantiene la grid de items, con un aire más "serio". */
.admin-card { border-top: 4px solid var(--coral, #ea7a63); }
.admin-list .more-item {
  /* Todos los items del panel admin salen ya destacados: no hace falta
   * marcar "gestion" o "solo-admin" para diferenciar del resto. */
  background: linear-gradient(135deg, var(--accent-soft), var(--pri-soft));
  border-color: var(--accent);
  color: var(--accent-d);
}
.admin-list .more-item:hover {
  background: linear-gradient(135deg, var(--accent-soft), var(--coral-soft, #ffe0dc));
  border-color: var(--coral, #ea7a63);
  color: var(--coral-d, #b0432b);
}
.admin-list .more-item.solo-admin::after { content: "ADMIN"; }
.admin-list .more-item.gestion::after {
  content: "GESTIÓN";
  position: absolute; top: 6px; right: 6px;
  font-size: 8px; font-weight: 900; letter-spacing: 0.12em;
  padding: 2px 5px;
  background: var(--pri);
  color: #fff;
  border-radius: 999px;
}

/* Cuando hay un sheet abierto, congela el scroll del body. */
body.sheet-open { overflow: hidden; }


/* =========================================================================
 * REDISEÑO — layout nuevo de la cabecera (`/estudio/`).
 *
 * Tres zonas fijas, siempre visibles: [nivel + XP] · [racha] · [avatar].
 * Cada métrica va en su propio "chip" (pastilla) para que respire y para
 * que se lea igual en móvil que en desktop. El anillo del nivel ya es la
 * barra de progreso visual, así que aquí NO duplicamos la barra plana
 * que había antes.
 *
 * Móvil (<640 px): las chips reducen padding y ocultan textos secundarios
 * (subtítulos como "Nivel", "de X XP" o "días"). En pantallas
 * ≤380 px la chip de nivel se contrae al mínimo (sólo el anillo).
 * ========================================================================= */

.topbar .hdr-left,
.topbar .hdr-center,
.topbar .hdr-right {
  display: flex; align-items: center;
}
.topbar .hdr-left    { justify-content: flex-start; min-width: 0; }
.topbar .hdr-center  { flex: 1; justify-content: center; min-width: 0; }
.topbar .hdr-right   { justify-content: flex-end; flex: 0 0 auto; }

/* Chip genérico de la topbar: superficie glass + halo suave.
 * Mismo tamaño visual para nivel y racha → lectura tranquila. */
.hdr-chip {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .05);
  min-width: 0;
  max-width: 100%;
  line-height: 1.05;
}
[data-theme="dark"] .hdr-chip { box-shadow: 0 1px 6px rgba(0, 0, 0, .35); }

/* Chip de nivel: anillo con el número dentro + XP total al lado.
 * En móviles muy estrechos escondemos el subtítulo "Nivel" y el
 * "de N XP" del siguiente umbral para que el chip no invada el
 * centro. */
xp-ring { display: inline-flex; align-items: center; flex: 0 0 auto; }
.level-chip .level-meta {
  display: flex; flex-direction: column; min-width: 0;
}
.level-chip .level-meta small {
  font-size: .7rem; font-weight: 600;
  color: var(--txt-soft);
  letter-spacing: .01em;
  white-space: nowrap;
}
.level-chip .level-meta small strong {
  color: var(--txt); font-weight: 800;
}
.level-chip .level-meta b {
  font-size: .95rem; font-weight: 800;
  color: var(--pri-d, var(--pri));
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .level-chip .level-meta b { color: var(--pri); }
.level-chip .level-meta b .of {
  color: var(--txt-soft);
  font-weight: 500;
  font-size: .78rem;
}

@media (max-width: 640px) {
  .level-chip { padding-right: 10px; }
  .level-chip .level-meta small { display: none; }
  .level-chip .level-meta b .of { display: none; }
  .level-chip .level-meta b { font-size: .82rem; }
}
@media (max-width: 380px) {
  .level-chip { padding: 3px; gap: 0; }
  .level-chip .level-meta { display: none; }
}

/* Fueguito de racha — misma "cáscara" que el chip de nivel. */
streak-flame { display: inline-flex; align-items: center; max-width: 100%; }
.flame {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .05);
  font-weight: 700;
  line-height: 1.05;
  transition: background .2s ease, border-color .2s ease, transform .15s ease;
}
[data-theme="dark"] .flame { box-shadow: 0 1px 6px rgba(0, 0, 0, .35); }

.flame .flame-emoji { font-size: 1.25rem; line-height: 1; filter: saturate(1.15); }
.flame .flame-days  { min-width: 1ch; text-align: center; font-size: 1.05rem; font-weight: 800; }
.flame-copy { display: flex; flex-direction: column; line-height: 1; }
.flame-copy small {
  font-size: .66rem; font-weight: 700; color: var(--txt-soft);
  letter-spacing: .04em; text-transform: uppercase;
}

/* Activa: gradiente cálido tipo llama + halo. */
.flame.on {
  background: linear-gradient(135deg, var(--coral-soft, #ffe0dc) 0%, var(--accent-soft) 100%);
  border-color: var(--coral, #ea7a63);
  color: var(--coral-d, #b0432b);
  box-shadow:
    0 2px 10px rgba(234, 122, 99, .28),
    0 0 0 3px rgba(234, 122, 99, .08);
  animation: flame-pulse 2.4s ease-in-out infinite;
}
.flame.on .flame-copy small { color: var(--coral-d, #b0432b); opacity: .85; }
[data-theme="dark"] .flame.on {
  background: linear-gradient(135deg, rgba(234, 122, 99, .22), rgba(244, 183, 64, .18));
  color: #ffd8cc;
}
[data-theme="dark"] .flame.on .flame-copy small { color: #ffd8cc; }

/* Apagada: chip discreto. */
.flame.off { color: var(--txt-soft); opacity: .8; }
.flame.off .flame-emoji { filter: grayscale(1); opacity: .6; }

@keyframes flame-pulse {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-1px); }
}
@media (prefers-reduced-motion: reduce) {
  .flame.on { animation: none; }
}

@media (max-width: 640px) {
  .flame { padding: 4px 11px; gap: .35rem; }
  .flame .flame-emoji { font-size: 1.15rem; }
  .flame .flame-days { font-size: .95rem; }
  .flame-copy small { display: none; }
}

/* Botón avatar (versión rediseñada — sólo la inicial). */
.topbar .user-btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  border-radius: 999px;
  padding: 3px;
  cursor: pointer;
  transition: background .12s ease, transform .12s ease, box-shadow .12s ease;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .05);
}
.topbar .user-btn:hover {
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(107, 142, 35, .22);
}
.topbar .user-btn .avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #4a6b16);
  color: white;
  font-weight: 800;
}
.topbar .user-btn .user-name { display: none; }

/* Escritorio: más aire entre chips, sin cambiar su tamaño. */
@media (min-width: 900px) {
  .topbar { padding: 0 2rem; gap: 1.5rem; }
  .topbar .hdr-center { justify-content: center; }
}
