:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --green: #22c55e;
  --green-dark: #15803d;
  --green-soft: #dcfce7;
  --red: #ef4444;
  --red-dark: #b91c1c;
  --red-soft: #fee2e2;
  --blue: #3b82f6;
  --blue-soft: #dbeafe;
  --gold: #f59e0b;
  --locked: #d1d5db;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --border-strong: #475569;
    --green-soft: #14532d;
    --red-soft: #7f1d1d;
    --blue-soft: #1e3a8a;
    --locked: #475569;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100%; position: relative; }
h2 { margin: 8px 0 16px; }
h3 { margin: 28px 0 10px; font-size: 1.05rem; }
.muted { color: var(--muted); font-size: .95rem; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; white-space: pre; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border-bottom: 2px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.01em; }
.brand b, .logo b { color: var(--green); }
.stats { display: flex; gap: 14px; }
.stat { display: flex; align-items: center; gap: 4px; font-weight: 700; }

/* Pantallas */
.screen { display: none; padding: 16px 16px 110px; }
.screen.active { display: block; }

.card-soft { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.daily-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
.bar { height: 14px; background: var(--border); border-radius: 99px; overflow: hidden; flex: 1; }
.bar-fill { height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .35s ease; }

/* Ruta */
.unit-header {
  margin: 28px 0 18px; padding: 16px 18px; border-radius: var(--radius); color: #fff;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18);
}
.unit-header .u-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; opacity: .9; font-weight: 700; }
.unit-header .u-sub { font-size: 1.25rem; font-weight: 800; }
.unit-header .u-progress { font-size: .9rem; opacity: .95; margin-top: 2px; }

.nodes { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.node-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.node {
  width: 76px; height: 72px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 32px; color: #fff; background: var(--c, var(--green));
  box-shadow: 0 6px 0 rgba(0,0,0,.22); transition: transform .08s, box-shadow .08s;
  position: relative;
}
.node:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.22); }
.node.locked { background: var(--locked); cursor: not-allowed; filter: grayscale(1); }
.node.current { animation: bob 1.6s ease-in-out infinite; outline: 4px solid var(--c, var(--green)); outline-offset: 5px; }
.node .check {
  position: absolute; right: -4px; bottom: -2px; background: var(--gold); width: 26px; height: 26px;
  border-radius: 50%; font-size: 14px; display: grid; place-items: center; border: 3px solid var(--bg);
}
.node-label { font-size: .85rem; font-weight: 700; text-align: center; max-width: 150px; color: var(--muted); }
.node-label.on { color: var(--text); }
@keyframes bob { 50% { transform: translateY(-5px); } }

/* Barra de navegación */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px; display: flex; background: var(--surface);
  border-top: 2px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tab {
  flex: 1; background: none; border: none; padding: 10px 0 12px; font: inherit; font-size: .8rem;
  font-weight: 700; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tab span { font-size: 1.4rem; }
.tab.active { color: var(--blue); }

/* Botones */
.btn {
  font: inherit; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; font-size: .92rem;
  border: none; border-radius: 14px; padding: 14px 18px; cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn.wide { width: 100%; }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-dark); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--green-dark); }
.btn.primary.wrong { background: var(--red); box-shadow: 0 4px 0 var(--red-dark); }
.btn:disabled { background: var(--border); color: var(--muted); box-shadow: 0 4px 0 var(--border-strong); cursor: default; }
.btn.secondary { background: var(--surface); color: var(--blue); border: 2px solid var(--border); box-shadow: 0 3px 0 var(--border); }
.btn.danger { background: transparent; color: var(--red); border: 2px solid var(--red-soft); margin-top: 20px; width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 150px; }
.icon-btn { background: none; border: none; font-size: 1.5rem; color: var(--muted); cursor: pointer; padding: 4px 8px; }

/* Perfil */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pstat { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px; color: var(--muted); font-size: .9rem; }
.pstat .big { font-size: 1.8rem; font-weight: 800; color: var(--text); }
.setting {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--green); }
.setting select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--border); background: var(--surface); color: var(--text); }

/* Lección */
.lesson {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  display: flex; flex-direction: column; max-width: 640px; margin: 0 auto;
}
.lesson[hidden] { display: none; }
.lesson-top { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.hearts { font-weight: 800; color: var(--red); white-space: nowrap; }
.hearts.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.lesson-body { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.lesson-foot { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); border-top: 2px solid var(--border); background: var(--bg); }
.lesson-foot.ok { background: var(--green-soft); border-color: transparent; }
.lesson-foot.bad { background: var(--red-soft); border-color: transparent; }
.feedback { display: none; margin-bottom: 12px; }
.feedback.show { display: block; }
.feedback .f-title { font-weight: 800; font-size: 1.15rem; }
.lesson-foot.ok .f-title { color: var(--green-dark); }
.lesson-foot.bad .f-title { color: var(--red-dark); }
@media (prefers-color-scheme: dark) {
  .lesson-foot.ok .f-title { color: #86efac; }
  .lesson-foot.bad .f-title { color: #fca5a5; }
}
.feedback .f-text { font-size: .95rem; margin-top: 4px; }

.kind { font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--blue); margin: 8px 0 6px; }
.question { font-size: 1.3rem; font-weight: 800; margin: 0 0 20px; }

.theory { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 20px; margin-top: 8px; }
.theory .t-icon { font-size: 2.6rem; }
.theory h2 { font-size: 1.3rem; margin: 8px 0 10px; }
.theory .t-body { font-size: 1.05rem; }
.dots { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.dots span.on { background: var(--blue); }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  font: inherit; text-align: left; background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-bottom-width: 4px; border-radius: 14px; padding: 14px 16px; cursor: pointer;
  display: flex; gap: 12px; align-items: center;
}
.option .key {
  flex: none; width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--border);
  display: grid; place-items: center; font-size: .8rem; font-weight: 800; color: var(--muted);
}
.option.sel { border-color: var(--blue); background: var(--blue-soft); }
.option.sel .key { border-color: var(--blue); color: var(--blue); }
.option.right { border-color: var(--green); background: var(--green-soft); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option:disabled { cursor: default; }
.tf { flex-direction: row; }
.tf .option { flex: 1; justify-content: center; font-weight: 800; font-size: 1.1rem; }

.fill-sentence { font-size: 1.25rem; font-weight: 700; margin-bottom: 20px; }
.blank { display: inline-block; min-width: 90px; border-bottom: 3px solid var(--blue); text-align: center; color: var(--blue); }

/* Ordenar */
.order-answer {
  min-height: 70px; border: 2px dashed var(--border-strong); border-radius: 14px; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px;
}
.order-answer:empty::before { content: "Toca las piezas en el orden correcto"; color: var(--muted); font-size: .95rem; padding: 12px 6px; }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; background: var(--surface); color: var(--text); border: 2px solid var(--border); border-bottom-width: 4px;
  border-radius: 12px; padding: 10px 14px; cursor: pointer; text-align: left;
}
.chip.used { visibility: hidden; }
.order-answer .chip { width: 100%; }
.order-answer .chip .n { color: var(--blue); font-weight: 800; margin-right: 6px; }
.order-answer.right { border-color: var(--green); border-style: solid; background: var(--green-soft); }
.order-answer.wrong { border-color: var(--red); border-style: solid; background: var(--red-soft); }

/* Emparejar */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: flex; flex-direction: column; gap: 10px; }
.match .chip { width: 100%; min-height: 58px; font-size: .95rem; }
.match .chip.sel { border-color: var(--blue); background: var(--blue-soft); }
.match .chip.done { border-color: var(--green); background: var(--green-soft); opacity: .55; cursor: default; }
.match .chip.bad { border-color: var(--red); background: var(--red-soft); animation: shake .35s; }

/* Final */
.finish { text-align: center; padding-top: 30px; }
.finish .big-emoji { font-size: 4.5rem; }
.finish h2 { font-size: 1.6rem; }
.finish-stats { display: flex; gap: 12px; justify-content: center; margin: 22px 0; }
.finish-stats div { border: 2px solid var(--border); border-radius: 14px; padding: 10px 16px; background: var(--surface); min-width: 100px; }
.finish-stats b { display: block; font-size: 1.4rem; }
.challenge { text-align: left; background: var(--surface); border: 2px solid var(--gold); border-radius: var(--radius); padding: 16px; margin-top: 10px; }
.challenge .c-title { font-weight: 800; color: var(--gold); margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: .95rem;
  max-width: calc(100% - 32px); text-align: center;
}

/* Cuenta y sincronización */
.sync-banner {
  width: 100%; margin-bottom: 12px; font: inherit; font-weight: 700; font-size: .95rem; text-align: left;
  background: var(--blue-soft); color: var(--text); border: 2px solid var(--blue); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer;
}
.sync-dot { font-size: 1rem; }
.account-box { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; }
.account-box p { margin: 0 0 12px; }
.field { display: block; margin-bottom: 12px; font-weight: 700; font-size: .9rem; }
.field input {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; padding: 12px;
  border-radius: 12px; border: 2px solid var(--border); background: var(--bg); color: var(--text);
}
.field input:focus { outline: none; border-color: var(--blue); }
.form-error { color: var(--red); font-size: .9rem; margin: 0 0 10px; min-height: 1em; }

/* ---------- Portada ---------- */
.landing, .auth { min-height: 100vh; padding: 0 16px 40px; }
.landing[hidden], .auth[hidden], #main-app[hidden] { display: none; }
.land-nav, .auth-top { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; }
.logo { font-weight: 800; font-size: 1.4rem; color: var(--text); text-decoration: none; letter-spacing: -.02em; display: flex; align-items: center; gap: 6px; }
.logo-mark { font-size: 1.5rem; }
.btn.small { padding: 9px 14px; font-size: .8rem; }
.btn.big { padding: 16px 22px; font-size: 1rem; }
.btn.ghost { background: transparent; color: var(--blue); border: 2px solid var(--border); box-shadow: 0 3px 0 var(--border); }
.link-btn { background: none; border: none; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; margin-top: 14px; padding: 6px; }

.hero { text-align: center; padding: 18px 0 36px; }
.mascot { position: relative; display: inline-flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
.bubble {
  background: var(--surface); border: 2px solid var(--border); border-radius: 16px; padding: 8px 14px;
  font-weight: 700; font-size: .95rem; position: relative; margin-bottom: 10px;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; width: 14px; height: 14px; background: var(--surface);
  border-right: 2px solid var(--border); border-bottom: 2px solid var(--border); transform: translateX(-50%) rotate(45deg);
}
.bot {
  font-size: 4.5rem; width: 128px; height: 128px; display: grid; place-items: center; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #86efac, var(--green)); box-shadow: 0 8px 0 var(--green-dark);
  animation: bob 2.4s ease-in-out infinite;
}
.hero h1 { font-size: clamp(1.8rem, 6.5vw, 2.6rem); line-height: 1.12; margin: 22px 0 12px; letter-spacing: -.02em; }
.hero .hl { color: var(--green); display: block; }
.lead { color: var(--muted); font-size: 1.08rem; max-width: 30em; margin: 0 auto 24px; }
.cta { display: flex; flex-direction: column; gap: 12px; max-width: 360px; margin: 0 auto; }
.cta[hidden] { display: none; }
.small-note { margin: 4px 0 0; font-size: .88rem; }

.land-section { padding: 26px 0; border-top: 2px solid var(--border); }
.land-section h2, .land-final h2 { text-align: center; font-size: 1.45rem; margin: 0 0 18px; }
.feature-grid { display: grid; gap: 14px; }
@media (min-width: 560px) { .feature-grid { grid-template-columns: repeat(3, 1fr); } }
.feature {
  background: var(--surface); border: 2px solid var(--border); border-bottom: 5px solid var(--c);
  border-radius: var(--radius); padding: 18px;
}
.feature h3 { margin: 8px 0 6px; font-size: 1.05rem; }
.feature p { margin: 0 0 12px; color: var(--muted); font-size: .95rem; }
.f-icon { font-size: 2rem; }
.f-tag { display: inline-block; font-size: .78rem; font-weight: 800; color: var(--c); text-transform: uppercase; letter-spacing: .05em; }

.steps { list-style: none; padding: 0; margin: 0 auto; max-width: 460px; display: flex; flex-direction: column; gap: 16px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; }
.s-num {
  flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--blue); color: #fff;
  font-weight: 800; display: grid; place-items: center; box-shadow: 0 3px 0 #1d4ed8;
}
.land-final { text-align: center; padding: 30px 20px; margin-top: 10px; background: var(--green-soft); border-radius: var(--radius); }
.land-foot { text-align: center; color: var(--muted); font-size: .9rem; padding-top: 26px; }

/* ---------- Iniciar sesión / Crear cuenta ---------- */
.auth-card {
  max-width: 420px; margin: 24px auto 0; background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 24px 20px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.auth-card > .muted { margin: 0 0 20px; }
.auth-card .btn.wide { margin-top: 4px; }
.hint { font-size: .85rem; color: var(--muted); margin: -4px 0 10px; }
.auth-closed { background: var(--red-soft); border-radius: 12px; padding: 10px 12px; font-size: .92rem; }
.auth-switch { text-align: center; margin: 18px 0 0; font-size: .95rem; color: var(--muted); }
.auth-switch a { color: var(--blue); font-weight: 800; text-decoration: none; }
.account-box .btn-row { margin-top: 4px; }
