:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #5d6862; /* 5.1:1 sobre --cream (antes 4.3:1) */
  --forest: #173f35;
  --forest-2: #24594b;
  --clay: #c56f45;
  --clay-ink: #9a4f2b; /* arcilla para texto pequeño: 5.2:1 sobre --cream */
  --sun: #e2a86f;
  --cream: #f4f0e8;
  --paper: #fffdf8;
  --line: #dcd7cb;
  --success: #34745a;
  --danger: #a74638;
  --shadow: 0 18px 45px rgba(23, 63, 53, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(226, 168, 111, .25), transparent 28rem),
    radial-gradient(circle at 92% 16%, rgba(36, 89, 75, .13), transparent 24rem),
    var(--cream);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.center-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-shell { width: min(100%, 460px); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center;
  color: var(--paper); background: var(--forest); font-weight: 900; font-size: 21px;
  box-shadow: 0 10px 24px rgba(23, 63, 53, .2);
}
.brand strong { display: block; letter-spacing: .03em; }
.brand span { color: var(--muted); font-size: .83rem; }
.card {
  background: rgba(255, 253, 248, .94);
  border: 1px solid rgba(220, 215, 203, .88);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.card.flat { box-shadow: none; }
.eyebrow { color: var(--clay-ink); text-transform: uppercase; font-weight: 800; letter-spacing: .12em; font-size: .72rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 7vw, 3.5rem); line-height: 1.02; letter-spacing: -.045em; }
h2 { font-size: 1.4rem; letter-spacing: -.025em; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.stack { display: grid; gap: 15px; }
.field { display: grid; gap: 7px; }
.field label, .label { font-weight: 750; font-size: .85rem; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 13px; background: #fff;
  padding: 12px 13px; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(36, 89, 75, .12); }
textarea { resize: vertical; min-height: 112px; }
.button {
  border: 0; border-radius: 13px; padding: 12px 16px; font-weight: 800;
  background: var(--forest); color: white; transition: transform .15s, background .15s;
}
.button:hover { background: var(--forest-2); transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.secondary { color: var(--forest); background: #e6eee9; }
.button.ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.button.danger { color: var(--danger); background: #f7e7e3; }
.button.small-button { padding: 8px 11px; border-radius: 10px; font-size: .8rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: #ece8df; margin-bottom: 18px; }
.segmented button { border: 0; padding: 9px; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 750; }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 3px 10px rgba(0,0,0,.06); }
.notice { border-left: 4px solid var(--sun); background: #fbf1df; padding: 11px 13px; border-radius: 8px 12px 12px 8px; font-size: .88rem; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center;
  padding: 14px max(18px, calc((100vw - 1120px) / 2)); background: rgba(244, 240, 232, .9);
  backdrop-filter: blur(16px); border-bottom: 1px solid rgba(220, 215, 203, .8);
}
.topbar .brand { margin: 0; }
.topbar .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 18px; }
.page { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 70px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }
.hero h1 { margin-bottom: 8px; }
.nav-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 20px; }
.nav-tabs button { white-space: nowrap; border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,.55); border-radius: 999px; padding: 9px 15px; font-weight: 750; }
.nav-tabs button.active { color: white; border-color: var(--forest); background: var(--forest); }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 28px 0 14px; }
.section-head h2 { margin: 0; }
.metric { min-height: 120px; }
.metric-value { font-size: 2rem; font-weight: 900; color: var(--forest); letter-spacing: -.04em; }
.progress-track { width: 100%; height: 10px; background: #e7e2d8; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--forest-2), var(--clay)); transition: width .3s ease; }
.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: .72rem; font-weight: 850; background: #eee9de; color: var(--muted); }
.status.completed { color: var(--success); background: #e3f0e8; }
.status.in_progress { color: #8a5a1f; background: #fbecd1; }
.status.missed { color: var(--danger); background: #f7e5e2; }
.run-card, .routine-card, .profile-card { display: grid; gap: 13px; align-content: start; }
.run-title { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: .82rem; }
.chip { display: inline-flex; padding: 6px 9px; border-radius: 999px; background: #eee9de; font-size: .75rem; font-weight: 750; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day-choice { position: relative; }
.day-choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.day-choice input:focus-visible + span { outline: 2px solid var(--color-primary-600); outline-offset: 2px; }
.day-choice span { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #eee9de; color: var(--muted); font-weight: 800; }
.day-choice input:checked + span { background: var(--forest); color: white; }
.steps-preview { margin: 0; padding-left: 20px; color: var(--muted); font-size: .88rem; }
.code-box { border: 1px dashed var(--clay); border-radius: 14px; padding: 14px; background: #fff8ec; text-align: center; }
.code { font-size: 1.6rem; letter-spacing: .15em; font-weight: 900; color: var(--forest); }
.hidden { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 32px 20px; }

.kids-shell { min-height: 100vh; background: linear-gradient(160deg, #f8efdb, #e6efe8); }
.kids-page { width: min(760px, calc(100% - 28px)); margin: 0 auto; padding: 24px 0 70px; }
.kids-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; }
.kids-greeting h1 { font-size: clamp(2.3rem, 10vw, 4.5rem); margin-bottom: 5px; }
.big-progress { display: grid; grid-template-columns: 88px 1fr; gap: 18px; align-items: center; margin-bottom: 24px; }
.progress-orb { width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; background: var(--forest); color: white; font-size: 1.25rem; font-weight: 900; box-shadow: var(--shadow); }
.journey { display: grid; gap: 18px; }
.kids-run { border-radius: 28px; padding: 22px; }
.kids-run.complete { background: #e7f1e9; border-color: #bcd6c3; }
.step-list { display: grid; gap: 10px; margin-top: 15px; }
.step-button { width: 100%; display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 12px; text-align: left; padding: 11px; border: 1px solid var(--line); border-radius: 15px; background: white; color: var(--ink); }
.step-button .check { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: #eee9de; font-size: 1.2rem; font-weight: 900; }
.step-button.done { color: var(--muted); text-decoration: line-through; }
.step-button.done .check { color: white; background: var(--success); text-decoration: none; }
.step-button:disabled { cursor: default; opacity: .82; }
.points-card { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; border-color: rgba(197, 111, 69, .35); background: linear-gradient(135deg, #fffaf0, #f5ead7); }
.celebration { text-align: center; padding: 22px; border-radius: 22px; background: var(--forest); color: white; margin: 20px 0; }
.celebration strong { display: block; font-size: 1.5rem; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translate(-50%, calc(100% + 48px)); width: min(440px, calc(100% - 32px)); padding: 13px 16px; border-radius: 14px; background: var(--ink); color: white; text-align: center; box-shadow: var(--shadow); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; }
.toast.show { transform: translate(-50%, 0); visibility: visible; transition-delay: 0s; }
.toast.error { background: var(--danger); }
.loader { width: 44px; height: 44px; border: 4px solid #d8d2c7; border-top-color: var(--forest); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .hero { align-items: start; flex-direction: column; }
  .page { width: min(100% - 24px, 1120px); padding-top: 22px; }
  .card { padding: 19px; border-radius: 20px; }
  .topbar { padding-inline: 13px; }
  .topbar .brand span { display: none; }
}

/* Design tokens - RAÍZ Rutinas (premium) */
:root {
  --color-primary-50: #f0fdf4;
  --color-primary-100: #dcfce7;
  --color-primary-200: #bbf7d0;
  --color-primary-300: #86efac;
  --color-primary-400: #4ade80;
  --color-primary-500: #22c55e;
  --color-primary-600: #16a34a;
  --color-primary-700: #15803d;
  --color-primary-800: #166534;
  --color-primary-900: #14532d;

  --color-secondary-50: #fff7ed;
  --color-secondary-100: #ffedd5;
  --color-secondary-200: #fed7aa;
  --color-secondary-300: #fdba74;
  --color-secondary-400: #fb923c;
  --color-secondary-500: #f97316;
  --color-secondary-600: #ea580c;
  --color-secondary-700: #c2410c;
  --color-secondary-800: #9a3412;
  --color-secondary-900: #7c2d12;

  --color-success: #16a34a;
  --color-warning: #f97316;
  --color-danger: #ef4444;
  --color-info: #3b82f6;

  --color-neutral-0: #ffffff;
  --color-neutral-50: #f8fafc;
  --color-neutral-100: #f1f5f9;
  --color-neutral-200: #e2e8f0;
  --color-neutral-300: #cbd5e1;
  --color-neutral-400: #94a3b8;
  --color-neutral-500: #64748b;
  --color-neutral-600: #475569;
  --color-neutral-700: #334155;
  --color-neutral-800: #1e293b;
  --color-neutral-900: #0f172a;

  --bg-adult: var(--color-neutral-50);
  --bg-adult-surface: var(--color-neutral-0);
  --bg-kids: radial-gradient(120% 120% at 50% 0%, #f0fdf4 0%, #f8fafc 100%);
  --bg-kids-surface: rgba(255,255,255,0.98);

  --text-primary: var(--color-neutral-900);
  --text-secondary: var(--color-neutral-700);
  --text-muted: var(--color-neutral-600);
  --text-inverse: var(--color-neutral-0);

  --border-subtle: var(--color-neutral-200);
  --border-strong: var(--color-neutral-300);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px -1px rgba(15,23,42,0.08);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,0.08), 0 2px 4px -2px rgba(15,23,42,0.08);
  --shadow-lg: 0 10px 15px -3px rgba(15,23,42,0.08), 0 4px 6px -4px rgba(15,23,42,0.08);
  --shadow-xl: 0 20px 25px -5px rgba(15,23,42,0.08), 0 8px 10px -6px rgba(15,23,42,0.08);

  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;
  --duration-slower: 500ms;
  --duration-celebration: 700ms;

  --ease-out: cubic-bezier(0.16,1,0.3,1);
  --ease-in-out: cubic-bezier(0.45,0,0.15,1);
  --ease-spring: cubic-bezier(0.175,0.885,0.32,1.275);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 2px solid var(--color-primary-600);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* Offline & Update banners */
.offline-banner, .update-banner {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--color-warning);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.update-banner {
  background: var(--color-primary-600);
  color: var(--text-inverse);
}

.update-banner button {
  margin-left: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.15);
  color: var(--text-inverse);
  cursor: pointer;
  font-weight: 600;
}

.update-banner button:hover {
  background: rgba(255,255,255,0.25);
}

/* CDE: mejoras visuales funcionales */
.badge {
  display:inline-flex;
  align-items:center;
  gap:var(--space-1);
  padding:4px 10px;
  border-radius:var(--radius-full);
  font-size:0.75rem;
  font-weight:700;
  background:#eee9de;
  color:var(--text-secondary);
  border:1px solid var(--border-subtle);
}
.badge-prem {
  background:var(--color-secondary-50);
  color:var(--color-secondary-700);
  border-color:var(--color-secondary-200);
}
.badge-resp {
  background:#e8f5e9;
  color:var(--color-primary-800);
  border-color:var(--color-primary-200);
}
.badge-pending {
  background:#fff3e0;
  color:#9a4d00;
  border-color:#ffcc80;
}
.kids-run.prem { border:1px solid var(--color-secondary-200); box-shadow:0 10px 15px -3px rgba(249,115,22,0.08); }
.kids-run.resp { border:1px solid var(--color-primary-200); box-shadow:var(--shadow-md); }
.step-button { transition:transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out); }
.step-button:active { transform:scale(0.98); }
.progress-fill { transition:width var(--duration-base) var(--ease-out); }

/* Multi-familia: selección, selector en el encabezado y cambio de contexto */
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.family-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.family-option {
  width: 100%; min-height: 64px; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 13px;
  padding: 10px 14px; text-align: left; color: var(--ink); background: white;
  border: 1px solid var(--line); border-radius: 18px;
  transition: transform var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.family-option:hover { border-color: var(--forest-2); box-shadow: 0 8px 20px rgba(23, 63, 53, .1); transform: translateY(-1px); }
.family-option:active { transform: scale(.99); }
.family-option[aria-current="true"] { border-color: var(--forest); background: #eef4f0; }
.family-option-text { display: grid; gap: 2px; min-width: 0; }
.family-option-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.family-option-go { color: var(--muted); font-weight: 900; transition: transform var(--duration-fast) var(--ease-out); }
.family-option:hover .family-option-go { transform: translateX(3px); color: var(--forest); }
.family-avatar {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none;
  color: var(--paper); background: linear-gradient(140deg, var(--forest-2), var(--clay)); font-weight: 900; font-size: 1.1rem;
}
.family-avatar.small { width: 28px; height: 28px; border-radius: 9px; font-size: .85rem; }
.disclosure { border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, .6); }
.disclosure > summary { min-height: 44px; display: flex; align-items: center; padding: 10px 14px; font-weight: 750; cursor: pointer; border-radius: 16px; }
.disclosure > form { padding: 4px 14px 16px; }
.switching { display: grid; justify-items: center; gap: 16px; color: var(--muted); font-weight: 750; }

.topbar { gap: 12px; }
.family-switch { position: relative; margin-left: auto; min-width: 0; }
.family-switch > summary {
  list-style: none; min-height: 44px; max-width: 280px; display: flex; align-items: center; gap: 9px; padding: 6px 12px 6px 8px;
  border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, .7); font-weight: 750; cursor: pointer;
}
.family-switch > summary::-webkit-details-marker { display: none; }
.family-switch > summary:hover, .family-switch[open] > summary { border-color: var(--forest-2); background: white; }
.family-switch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.family-switch-caret { width: 8px; height: 8px; margin: 0 2px 4px 2px; flex: none; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform var(--duration-fast) var(--ease-out); }
.family-switch[open] .family-switch-caret { transform: translateY(4px) rotate(225deg); }
.family-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: min(300px, calc(100vw - 26px)); display: grid; gap: 2px;
  padding: 10px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow);
  animation: menu-in var(--duration-fast) var(--ease-out);
}
.family-menu .eyebrow { padding: 4px 8px 6px; }
.family-menu button {
  min-height: 44px; display: grid; grid-template-columns: 22px 1fr; align-items: center; gap: 8px; padding: 8px;
  text-align: left; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font-weight: 650;
}
.family-menu button:hover { background: #eef4f0; }
.family-menu button[aria-current="true"] { font-weight: 850; color: var(--forest); }
.family-menu-check { color: var(--forest); font-weight: 900; text-align: center; }
.family-menu hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } }
.confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.confirm-dialog::backdrop { background: rgba(23, 35, 31, .45); }
.invite-link { margin: 8px 0 12px; font-size: .82rem; font-weight: 700; color: var(--forest); overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .topbar .brand strong { display: none; }
  .family-switch { flex: 1; }
  .family-switch > summary { max-width: none; }
  .family-menu { left: 0; right: auto; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
}

/* Objetivos táctiles: mínimo 44 × 44 px (PRODUCT.md) en todo control accionable */
.button, .nav-tabs button, .segmented button, .update-banner button {
  min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; text-decoration-skip-ink: auto;
}
.button.small-button { padding: 8px 14px; }
.segmented button { display: flex; }
input, select { min-height: 44px; }
.day-choice span { width: 44px; height: 44px; }

/* Los banners viven después de #app: con sticky quedaban al final del documento, fuera de
   la vista. Fijos abajo se ven siempre y no tapan el encabezado ni el selector de familia. */
.offline-banner, .update-banner {
  position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 90;
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
}

/* --- Acceso por perfiles --- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.link-button {
  min-height: 44px; padding: 8px 4px; border: 0; background: none; color: var(--forest); font-weight: 750;
  text-align: left; text-decoration: underline; text-underline-offset: 3px;
}
.link-button:hover { color: var(--forest-2); }
.auth-links { display: grid; justify-items: start; border-top: 1px solid var(--line); padding-top: 8px; }

.avatar {
  --tone: linear-gradient(140deg, var(--forest-2), var(--forest));
  width: 56px; height: 56px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--tone); color: var(--paper); font-weight: 900; font-size: 1.6rem; line-height: 1;
}
.avatar.tiny { width: 28px; height: 28px; font-size: .85rem; }
.avatar.small { width: 44px; height: 44px; font-size: 1.25rem; }
.avatar.large { width: 112px; height: 112px; font-size: 3.2rem; }
.av-sprout { --tone: linear-gradient(140deg, #d9efd6, #a9d8a4); }
.av-leaf { --tone: linear-gradient(140deg, #d3ebe0, #8fc9ae); }
.av-flower { --tone: linear-gradient(140deg, #fbe1e6, #f1b3c1); }
.av-sun { --tone: linear-gradient(140deg, #fdeec4, #f3c66a); }
.av-moon { --tone: linear-gradient(140deg, #dfe3f6, #aab3e0); }
.av-star { --tone: linear-gradient(140deg, #fff1cf, #eccb7a); }
.av-fox { --tone: linear-gradient(140deg, #fbdcc7, #eda677); }
.av-bird { --tone: linear-gradient(140deg, #d6ecf8, #96c8e6); }
.av-cat { --tone: linear-gradient(140deg, #fde6cf, #f2b98a); }
.av-dog { --tone: linear-gradient(140deg, #f3e3d0, #d9b48c); }
.av-rabbit { --tone: linear-gradient(140deg, #f6e6ee, #e3b7cd); }
.av-bear { --tone: linear-gradient(140deg, #eedfcf, #c9a37f); }
.av-lion { --tone: linear-gradient(140deg, #fdeac2, #eeb95c); }
.av-turtle { --tone: linear-gradient(140deg, #d8efdc, #93cf9f); }
.av-butterfly { --tone: linear-gradient(140deg, #dbe8fb, #9dbdee); }
.av-fish { --tone: linear-gradient(140deg, #d3eef3, #86cfdc); }
.av-owl { --tone: linear-gradient(140deg, #e9e0d3, #bfa687); }
.av-bee { --tone: linear-gradient(140deg, #fff0bf, #f0cf5e); }
.av-tree { --tone: linear-gradient(140deg, #d6ecd2, #8fc487); }
.av-cactus { --tone: linear-gradient(140deg, #dcefd3, #a3cf8c); }
.av-rainbow { --tone: linear-gradient(140deg, #e6e2f8, #bcaee8); }
.av-rocket { --tone: linear-gradient(140deg, #e0e4f1, #a9b3d6); }
.av-ball { --tone: linear-gradient(140deg, #e3efe0, #a8cfa0); }
.av-music { --tone: linear-gradient(140deg, #f1e0f3, #d2a6d8); }
.av-add { --tone: transparent; border: 2px dashed rgba(255, 253, 248, .55); font-weight: 400; }

.profiles-shell {
  min-height: 100vh; display: flex; flex-direction: column; padding: 20px 16px 40px; color: var(--paper);
  background:
    radial-gradient(circle at 15% 0%, rgba(226, 168, 111, .22), transparent 26rem),
    radial-gradient(circle at 90% 100%, rgba(52, 116, 90, .5), transparent 30rem),
    #12322a;
}
.profiles-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.profiles-top .brand { margin: 0; }
.profiles-top .brand-mark { background: var(--paper); color: var(--forest); }
.profiles-top .chip { background: rgba(255, 253, 248, .14); color: var(--paper); }
.profiles-stage { flex: 1; display: grid; align-content: center; justify-items: center; gap: 34px; padding-block: 28px; text-align: center; }
.profiles-stage h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 3rem); outline: none; }
.profile-grid {
  list-style: none; margin: 0; padding: 0; width: min(100%, 880px);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 22px 28px;
}
.profile-tile {
  width: 136px; min-height: 44px; display: grid; justify-items: center; gap: 6px; padding: 8px 4px;
  border: 0; border-radius: 20px; background: none; color: inherit;
}
.profile-tile strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.profile-note { font-size: .8rem; color: rgba(255, 253, 248, .78); }
.profile-face { position: relative; display: block; margin-bottom: 6px; border-radius: 50%; transition: transform .18s, box-shadow .18s; }
.profile-tile:hover .profile-face, .profile-tile:focus-visible .profile-face {
  transform: scale(1.06); box-shadow: 0 0 0 4px var(--paper);
}
.profile-tile:focus-visible { outline: none; }
.profile-tile:active .profile-face { transform: scale(.98); }
.profile-lock {
  position: absolute; right: 2px; bottom: 2px; width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 50%; background: var(--paper); font-size: .85rem; box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.profiles-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.button.on-dark { background: rgba(255, 253, 248, .12); color: var(--paper); border: 1px solid rgba(255, 253, 248, .4); }
.button.on-dark:hover { background: rgba(255, 253, 248, .22); }
.button.on-dark.quiet { border-color: transparent; background: none; text-decoration: underline; text-underline-offset: 3px; }
.button.on-dark:focus-visible, .link-button:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.profiles-hint { margin: 0; font-size: .85rem; color: rgba(255, 253, 248, .78); }

.pin-dialog form { justify-items: center; text-align: center; }
.pin-dialog .field { width: 100%; }
.pin-dialog input { text-align: center; letter-spacing: .5em; font-size: 1.4rem; }
.pin-error { min-height: 1.3em; margin: 0; color: var(--danger); font-weight: 750; font-size: .9rem; }

.hero-profile { display: flex; align-items: center; gap: 16px; min-width: 0; }
.avatar-edit { position: relative; flex: none; padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; }
.avatar-edit:focus-visible { outline: 3px solid var(--clay); outline-offset: 3px; }
.avatar-pencil {
  position: absolute; right: -4px; bottom: -4px; display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; background: var(--paper); box-shadow: 0 2px 8px rgba(23, 61, 54, .22); font-size: .9rem;
}
.hero-profile h1, .hero-profile h3 { margin-bottom: 4px; }
.profile-switch { display: inline-flex; align-items: center; gap: 8px; }
.attention { display: flex; align-items: center; gap: 16px; text-align: left; color: inherit; border: 1px solid var(--line); width: 100%; min-height: 44px; }
.attention:hover { border-color: var(--forest-2); }
.attention > span:last-child { display: grid; gap: 2px; }
.family-progress { display: flex; align-items: center; gap: 14px; }
.family-progress > div { flex: 1; display: grid; gap: 6px; min-width: 0; }
.avatar-picker { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.avatar-picker legend { padding: 0; margin-bottom: 7px; }
.avatar-choice { position: relative; display: block; border-radius: 50%; cursor: pointer; }
.avatar-choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.avatar-choice .avatar { border: 3px solid transparent; }
.avatar-choice input:checked + .avatar { border-color: var(--forest); box-shadow: 0 0 0 2px var(--paper) inset; }
.avatar-choice input:focus-visible + .avatar { outline: 3px solid var(--clay); outline-offset: 2px; }
.profile-card .disclosure { margin-block: 10px; }

@media (max-width: 760px) {
  .avatar.large { width: 88px; height: 88px; font-size: 2.5rem; }
  .profile-grid { gap: 16px 10px; }
  .profile-tile { width: 108px; }
  .kids-greeting.hero-profile { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .profile-face { transition: none; }
  .profile-tile:hover .profile-face, .profile-tile:focus-visible .profile-face { transform: none; }
}
.session-end { margin-top: 28px; display: flex; justify-content: center; }

/* --- Espacio personal del adulto --- */
.button-row.center { justify-content: center; }
.habit-card { display: grid; gap: 12px; }
.habit-week { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; }
.habit-dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; font-weight: 800; background: #eee9de; color: var(--muted); }
.habit-dot.done { background: var(--success); color: white; }
.habit-dot.open { background: transparent; border: 2px solid var(--line); }
.habit-dot.off { opacity: .45; }
.day-bars { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 6px; align-items: end; }
.day-bar { display: grid; gap: 6px; justify-items: center; }
.day-bar-track { width: 100%; max-width: 34px; height: 120px; border-radius: 10px; background: #eee9de; display: flex; align-items: flex-end; overflow: hidden; }
.day-bar-fill { width: 100%; background: linear-gradient(180deg, var(--forest-2), var(--forest)); border-radius: 10px 10px 0 0; transition: height .25s ease; }
.day-bar.off .day-bar-track { background: repeating-linear-gradient(135deg, #f1ede4, #f1ede4 5px, #e9e4d9 5px, #e9e4d9 10px); }
.day-bar-label { font-size: .72rem; font-weight: 750; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.plain-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.plain-table th, .plain-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.plain-table thead th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.plain-table tbody tr:last-child th, .plain-table tbody tr:last-child td { border-bottom: 0; }
.assignee-field { border: 0; margin: 0; padding: 0; min-width: 0; }
.assignee-field legend { padding: 0; margin-bottom: 7px; }
.assignees { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.assignee-choice { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-weight: 700; cursor: pointer; }
.assignee-choice { position: relative; }
.assignee-choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.assignee-choice:has(input:checked) > span::before { content: '✓ '; font-weight: 900; color: var(--forest); }
.assignee-choice:has(input:checked) { border-color: var(--forest); background: #e6eee9; }
.assignee-choice:has(input:focus-visible) { outline: 3px solid var(--clay); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .day-bar-fill { transition: none; } }


/* ==========================================================================
   Vista infantil. Estilo «clay»: formas redondas y gruesas, borde marcado,
   color vivo y rebote al tocar. Todo vive bajo .kids-shell para no tocar las
   pantallas de adultos. Dos experiencias: .mode-peques y .mode-exploradores.
   ========================================================================== */
@font-face {
  font-family: "Baloo 2"; font-style: normal; font-weight: 500 800; font-display: swap;
  src: url("/fonts/baloo2-latin.woff2") format("woff2");
}
.kids-shell {
  --k-font: "Baloo 2", ui-rounded, "SF Pro Rounded", "Trebuchet MS", system-ui, sans-serif;
  --k-ink: #2b2140;
  --k-soft: #5a4f73;            /* 6.6:1 sobre blanco */
  --k-primary: #6d28d9;         /* blanco encima: 7.1:1 */
  --k-primary-deep: #4c1d95;
  --k-sun: #ffc93c;
  --k-sun-deep: #b45309;
  --k-done: #047857;            /* blanco encima: 5.5:1 */
  --k-card: #ffffff;
  --k-edge: #2b2140;
  --k-radius: 28px;
  font-family: var(--k-font); color: var(--k-ink);
  background:
    radial-gradient(circle at 12% 8%, #ffd9a8 0 9rem, transparent 9.1rem),
    radial-gradient(circle at 92% 22%, #c9b8ff 0 7rem, transparent 7.1rem),
    radial-gradient(circle at 80% 88%, #a8ecd0 0 10rem, transparent 10.1rem),
    linear-gradient(165deg, #fff6dd, #ffe7f0 55%, #e6f0ff);
}
.kids-shell.mode-exploradores {
  --k-primary: #1d4ed8;         /* blanco encima: 6.7:1 */
  --k-primary-deep: #1e3a8a;
  --k-sun: #5eead4;
  --k-sun-deep: #0f766e;
  background:
    radial-gradient(circle at 10% 10%, #b9d7ff 0 8rem, transparent 8.1rem),
    radial-gradient(circle at 94% 30%, #c7f5e6 0 7rem, transparent 7.1rem),
    radial-gradient(circle at 20% 92%, #ddd0ff 0 9rem, transparent 9.1rem),
    linear-gradient(165deg, #eef5ff, #eeeaff 60%, #e3fbf3);
}
.kids-shell h1, .kids-shell h2, .kids-shell h3, .kids-shell strong, .kids-shell button { font-family: var(--k-font); }
.kids-shell .muted { color: var(--k-soft); }
.kids-shell .eyebrow { color: var(--k-primary); font-weight: 800; letter-spacing: .06em; }
.kids-shell .brand-mark { background: var(--k-primary); border-radius: 16px; box-shadow: 0 4px 0 var(--k-primary-deep); }
.kids-shell .kids-header .button { border: 3px solid var(--k-edge); border-radius: 18px; background: #fff; color: var(--k-ink); box-shadow: 0 4px 0 var(--k-edge); font-weight: 700; }

/* Saludo */
.kids-shell .kids-greeting { margin-bottom: 20px; }
.kids-shell .kids-greeting h1 { color: var(--k-primary-deep); line-height: 1; font-weight: 800; }
.kids-shell .avatar-edit .avatar { border: 4px solid var(--k-edge); box-shadow: 0 6px 0 var(--k-edge); }
.kids-shell .avatar-pencil { border: 3px solid var(--k-edge); background: var(--k-sun); width: 34px; height: 34px; box-shadow: none; }

/* Avance */
.kids-shell .big-progress {
  padding: 18px; border: 3px solid var(--k-edge); border-radius: var(--k-radius); background: var(--k-card);
  box-shadow: 0 7px 0 var(--k-edge);
}
.kids-shell .progress-orb {
  color: var(--k-ink); font-size: 1.35rem; box-shadow: none; border: 3px solid var(--k-edge);
  background: radial-gradient(circle, #fff 0 56%, transparent 57%), conic-gradient(var(--k-done) calc(var(--p, 0) * 1%), #ece6f7 0);
}
.kids-shell .progress-track { height: 16px; border: 3px solid var(--k-edge); background: #fff; }
.kids-shell .progress-fill { background: linear-gradient(90deg, var(--k-sun), var(--k-done)); }
.star-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 8px; font-size: 1.9rem; line-height: 1; }
.star { color: #e3dcef; -webkit-text-stroke: 2px var(--k-edge); paint-order: stroke fill; }
.star.on { color: var(--k-sun); }

/* Puntos */
.kids-shell .card.points-card {
  justify-content: flex-start; border: 3px solid var(--k-edge); border-radius: var(--k-radius);
  background: linear-gradient(135deg, #fff3bf, #ffd88a); box-shadow: 0 7px 0 var(--k-edge);
}
.kids-shell.mode-exploradores .points-card { background: linear-gradient(135deg, #d6fbf1, #a7efe0); }
.kids-shell .points-card .metric-value { color: var(--k-ink); font-size: 2.6rem; line-height: 1; }
.kids-shell .points-card .eyebrow { color: var(--k-ink); }
.kids-shell .points-card > .muted { margin-left: auto; color: var(--k-ink); text-align: right; }
.coin {
  flex: none; display: grid; place-items: center; width: 62px; height: 62px; border-radius: 50%;
  border: 3px solid var(--k-edge); background: radial-gradient(circle at 35% 30%, #fff7c2, var(--k-sun) 70%);
  color: var(--k-ink); font-size: 2rem; line-height: 1; box-shadow: 0 5px 0 var(--k-edge);
}

/* Tarjetas */
.kids-shell .card { border: 3px solid var(--k-edge); border-radius: var(--k-radius); background: var(--k-card); box-shadow: 0 7px 0 var(--k-edge); }
.kids-shell .card.empty { box-shadow: none; border-style: dashed; background: rgba(255, 255, 255, .7); color: var(--k-soft); }
.kids-shell .kids-run.tone-0 { background: #fff1e0; }
.kids-shell .kids-run.tone-1 { background: #e3f1ff; }
.kids-shell .kids-run.tone-2 { background: #e2f9ea; }
.kids-shell .kids-run.tone-3 { background: #f3e8ff; }
.kids-shell .kids-run.complete { background: #d6f5e3; border-color: var(--k-done); box-shadow: 0 7px 0 var(--k-done); }
.kids-shell .kids-run h2 { font-size: 1.6rem; font-weight: 800; }
.kids-shell .notice { border: 2px solid var(--k-edge); border-radius: 16px; background: #fff; color: var(--k-ink); }
.kids-shell .status, .kids-shell .chip { border: 2px solid var(--k-edge); background: #fff; color: var(--k-ink); font-weight: 800; font-size: .8rem; }
.kids-shell .status.completed { background: var(--k-done); color: #fff; }
.kids-shell .section-head h2 { font-size: 1.5rem; font-weight: 800; color: var(--k-primary-deep); }
.kids-shell .section-head .muted { color: var(--k-soft); }
.section-icon { display: inline-block; margin-right: 8px; }

/* Pasos: lo que más se toca */
.kids-shell .step-button {
  min-height: 64px; grid-template-columns: 52px 1fr; padding: 8px 12px 8px 8px; border: 3px solid var(--k-edge);
  border-radius: 20px; background: #fff; color: var(--k-ink); font-size: 1.1rem; font-weight: 700;
  box-shadow: 0 5px 0 var(--k-edge); transition: transform 160ms cubic-bezier(.34, 1.56, .64, 1), box-shadow 160ms ease-out;
  touch-action: manipulation;
}
.kids-shell .step-button .check { width: 52px; height: 52px; border-radius: 16px; border: 3px solid var(--k-edge); background: #f4eefc; font-size: 1.4rem; }
.kids-shell .step-button:active:not(:disabled) { transform: translateY(4px) scale(.99); box-shadow: 0 1px 0 var(--k-edge); }
.kids-shell .step-button.done { background: #e3f8ec; color: var(--k-ink); text-decoration: none; }
.kids-shell .step-button.done > span:last-child { text-decoration: line-through; text-decoration-thickness: 2px; }
.kids-shell .step-button.done .check { background: var(--k-done); color: #fff; }
.kids-shell .step-button:focus-visible, .kids-shell .button:focus-visible, .kids-shell .avatar-edit:focus-visible { outline: 4px solid var(--k-sun-deep); outline-offset: 3px; }

/* Botones */
.kids-shell main .button {
  min-height: 52px; border: 3px solid var(--k-edge); border-radius: 18px; background: var(--k-primary); color: #fff;
  font-size: 1.05rem; font-weight: 800; box-shadow: 0 5px 0 var(--k-edge);
  transition: transform 160ms cubic-bezier(.34, 1.56, .64, 1), box-shadow 160ms ease-out; touch-action: manipulation;
}
.kids-shell main .button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--k-edge); }
.kids-shell main .button.ghost { background: #fff; color: var(--k-ink); }
.kids-shell main .button:disabled { background: #efeaf6; color: var(--k-soft); box-shadow: none; border-style: dashed; opacity: 1; }

/* Día completo */
.kids-shell .celebration {
  border: 3px solid var(--k-edge); border-radius: var(--k-radius); color: var(--k-ink);
  background: linear-gradient(135deg, #fff3bf, #ffd0e4 50%, #cfe4ff); box-shadow: 0 7px 0 var(--k-edge);
}
.kids-shell .celebration strong { font-size: 1.8rem; font-weight: 800; }
.confetti { display: block; font-size: 2.6rem; line-height: 1; }

/* Peques: menos texto, todo más grande, una sola columna */
.mode-peques .kids-greeting h1 { font-size: clamp(2.8rem, 13vw, 5rem); }
.mode-peques .kids-greeting .muted { font-size: 1.25rem; font-weight: 700; }
.mode-peques .progress-orb { display: none; }
.mode-peques .big-progress { grid-template-columns: 1fr; }
.mode-peques .big-progress h2 { font-size: 1.7rem; font-weight: 800; }
.mode-peques .big-progress .muted { font-size: 1.05rem; font-weight: 700; }
.mode-peques .kids-run h2 { font-size: 1.9rem; }
.mode-peques .step-button { min-height: 80px; grid-template-columns: 64px 1fr; font-size: 1.35rem; border-radius: 24px; }
.mode-peques .step-button .check { width: 64px; height: 64px; font-size: 1.8rem; border-radius: 20px; }
.mode-peques main .button { min-height: 64px; font-size: 1.25rem; border-radius: 22px; }
.mode-peques .grid.two { grid-template-columns: 1fr; }
.mode-peques .points-card > .muted, .mode-peques .section-head .muted { display: none; }
.mode-peques .points-card .metric-value { font-size: 3.4rem; }
.mode-peques .coin { width: 76px; height: 76px; font-size: 2.5rem; }
.mode-peques .routine-card h3 { font-size: 1.4rem; }

/* Exploradores: más compacto y con aire de misión */
.mode-exploradores .kids-greeting h1 { font-size: clamp(2rem, 8vw, 3.4rem); }
.mode-exploradores .big-progress { background: linear-gradient(135deg, #ffffff, #eaf2ff); }
.mode-exploradores .kids-run h2 { font-size: 1.35rem; }
.mode-exploradores .step-button { min-height: 56px; grid-template-columns: 44px 1fr; font-size: 1rem; }
.mode-exploradores .step-button .check { width: 44px; height: 44px; font-size: 1.15rem; border-radius: 14px; }

@media (prefers-reduced-motion: no-preference) {
  .kids-shell .step-button.done .check { animation: k-pop 320ms cubic-bezier(.34, 1.56, .64, 1); }
  .star.on { animation: k-pop 320ms cubic-bezier(.34, 1.56, .64, 1); }
  .coin { animation: k-float 3.2s ease-in-out infinite; }
  .confetti { animation: k-pop 500ms cubic-bezier(.34, 1.56, .64, 1); }
}
@keyframes k-pop { 0% { transform: scale(.4); } 100% { transform: scale(1); } }
@keyframes k-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) {
  .kids-shell .step-button, .kids-shell main .button { transition: none; }
}
@media (max-width: 420px) {
  .kids-shell .points-card > .muted { display: none; }
  .star-row { font-size: 1.6rem; }
}
