/* ============================================================
   5X — Aprende más rápido · Estilos
   Paleta: azul noche #0a0e1a · dorado #d4af37 · violeta neurona #7b5cff
   Mobile-first · solo fuentes del sistema (funciona offline)
   ============================================================ */
:root {
  --night: #0a0e1a;
  --night-2: #11182b;
  --night-3: #1a2340;
  --gold: #d4af37;
  --gold-soft: #e8c96a;
  --violet: #7b5cff;
  --text: #f2ecdd;
  --muted: #9aa3bd;
  --ok: #3ddc84;
  --danger: #ff6b6b;
  --radius: 16px;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, .tab, .check, .del, input, textarea, select, .dot { touch-action: manipulation; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--night);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); /* espacio para la tabbar */
  line-height: 1.55;
}

/* Fondo de neuronas fijo y sutil */
.bg-neurons {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(1200px 600px at 50% -10%, #16204a 0%, var(--night) 60%);
}
.bg-neurons svg { width: 100%; height: 100%; }

/* ---------- Cabecera ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(10, 14, 26, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-family: var(--serif); font-weight: bold; font-size: 1.5rem;
  color: var(--night);
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 18px rgba(212, 175, 55, 0.45);
}
.brand-text strong { font-family: var(--serif); font-size: 1.05rem; letter-spacing: 0.3px; display: block; }
.brand-text small { color: var(--muted); font-size: 0.72rem; }

.btn-install {
  background: transparent; color: var(--gold);
  border: 1px solid var(--gold); border-radius: 999px;
  padding: 8px 14px; font-size: 0.8rem; cursor: pointer;
}

/* ---------- Vistas ---------- */
main { max-width: 560px; margin: 0 auto; padding: 18px 16px 8px; }
.view h1 {
  font-family: var(--serif); font-weight: normal;
  font-size: 1.7rem; margin: 6px 0 2px; color: var(--gold-soft);
  letter-spacing: 0.3px;
}
.view h3 { font-family: var(--serif); font-weight: normal; color: var(--gold); margin: 20px 0 8px; font-size: 1.1rem; }
.subtitle, .muted { color: var(--muted); font-size: 0.9rem; margin-top: 0; }

/* ---------- Tarjetas ---------- */
.card {
  background: linear-gradient(160deg, var(--night-2), var(--night-3));
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: var(--radius);
  padding: 16px; margin: 12px 0;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.card h3 { margin-top: 0; }

/* ---------- Botones ---------- */
.btn {
  font-family: var(--sans); font-size: 0.95rem;
  background: var(--night-3); color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 12px; padding: 12px 16px; cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  color: #1a1405; border: none; font-weight: 700;
  box-shadow: 0 4px 18px rgba(212, 175, 55, 0.35);
}
.btn-big { width: 100%; margin: 10px 0; font-size: 1.02rem; padding: 14px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 7px 10px; font-size: 0.8rem; border-radius: 9px; }

/* ---------- Formularios ---------- */
.input, textarea.input, select.input {
  width: 100%; background: #0d1322; color: var(--text);
  border: 1px solid rgba(212, 175, 55, 0.3); border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; font-family: var(--sans);
  margin: 6px 0;
}
.input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212,175,55,0.25); }
.input::placeholder { color: #5d6578; }
.field-label { display: block; font-size: 0.82rem; color: var(--gold-soft); margin: 12px 0 2px; font-weight: 600; }
.add-row { display: flex; gap: 8px; margin: 10px 0; }
.add-row .input { flex: 1; margin: 0; }

/* ---------- Inicio ---------- */
.streak-card { display: flex; gap: 16px; align-items: center; border-color: rgba(212,175,55,0.45); }
.streak-flame { font-size: 2.6rem; filter: drop-shadow(0 0 10px rgba(255,150,50,0.6)); }
.streak-flame.off { filter: grayscale(1); opacity: 0.4; }
.streak-num { font-size: 1.6rem; font-family: var(--serif); color: var(--gold-soft); }
.streak-num small { font-size: 0.85rem; color: var(--muted); font-family: var(--sans); }
.streak-sub { font-size: 0.82rem; color: var(--muted); }
.moti { text-align: center; color: var(--gold-soft); font-style: italic; min-height: 1.4em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { text-align: center; margin: 0; }
.stat-num { display: block; font-family: var(--serif); font-size: 2rem; color: var(--gold); }
.stat-label { font-size: 0.8rem; color: var(--muted); }

/* ---------- Temporizador ---------- */
.timer-card { text-align: center; }
.phase-label {
  font-family: var(--serif); font-size: 1.25rem; color: var(--gold-soft);
  letter-spacing: 0.5px; margin-bottom: 6px;
}
.ring-wrap { position: relative; width: 220px; height: 220px; margin: 8px auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(212,175,55,0.15); stroke-width: 10; }
.ring-fg {
  fill: none; stroke: url(#goldgrad); stroke: var(--gold); stroke-width: 10;
  stroke-linecap: round; transition: stroke-dashoffset 0.5s linear;
  filter: drop-shadow(0 0 8px rgba(212,175,55,0.55));
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.time { font-family: var(--serif); font-size: 2.9rem; color: var(--text); letter-spacing: 2px; }
.phase-sub { color: var(--muted); font-size: 0.82rem; max-width: 170px; }
.phase-dots { display: flex; justify-content: center; gap: 10px; margin: 14px 0 4px; }
.dot {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(212,175,55,0.4); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}
.dot.active { background: linear-gradient(135deg, var(--gold-soft), var(--gold)); color: #1a1405; border: none; }
.dot.done { border-color: var(--ok); color: var(--ok); }
.tip { font-size: 1.02rem; color: var(--text); }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(26, 35, 64, 0.7);
  border: 1px solid rgba(212,175,55,0.15);
  border-radius: 12px; padding: 10px 12px;
}
.item .txt { flex: 1; }
.item .txt small { display: block; color: var(--muted); font-size: 0.75rem; }
.item.done .txt { text-decoration: line-through; color: var(--muted); }
.check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--gold); background: transparent; cursor: pointer;
  color: transparent; font-size: 0.9rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.check.on { background: var(--gold); color: #1a1405; }
.del { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px; }
.del:hover { color: var(--danger); }
.empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 14px; }
.counter-line { text-align: center; color: var(--muted); }
.badge {
  font-size: 0.7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: rgba(123, 92, 255, 0.2); color: #c9bfff; border: 1px solid rgba(123,92,255,0.4);
  white-space: nowrap;
}
.badge.today { background: rgba(212,175,55,0.2); color: var(--gold-soft); border-color: var(--gold); }

/* ---------- Plantillas ---------- */
.tpl-menu { display: grid; gap: 10px; }
.tpl-btn { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; text-align: left; cursor: pointer; width: 100%; color: var(--text); font-family: var(--sans); }
.tpl-btn strong { font-family: var(--serif); font-weight: normal; font-size: 1.05rem; color: var(--gold-soft); }
.tpl-btn small { color: var(--muted); grid-column: 2; }
.tpl-emoji { font-size: 1.7rem; grid-row: span 2; align-self: center; }
.tpl-actions { display: flex; gap: 8px; margin-top: 10px; }
.score { font-family: var(--serif); font-size: 1.3rem; color: var(--gold); text-align: center; margin: 10px 0; }
.checkline { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid rgba(212,175,55,0.12); }
.checkline:last-child { border-bottom: none; }
.checkline label { flex: 1; font-size: 0.92rem; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: rgba(10, 14, 26, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(212, 175, 55, 0.25);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 8px; color: var(--muted); font-size: 1.15rem;
}
.tab small { font-size: 0.62rem; letter-spacing: 0.4px; }
.tab.active { color: var(--gold); }
.tab.active small { color: var(--gold-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: var(--night-3); color: var(--text);
  border: 1px solid var(--gold); border-radius: 999px;
  padding: 10px 20px; font-size: 0.9rem; white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- Gamificación ---------- */
.level-card { border-color: rgba(212,175,55,0.45); }
.level-head { display: flex; gap: 14px; align-items: center; }
.level-icon {
  font-size: 2.2rem; width: 58px; height: 58px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 35% 30%, rgba(212,175,55,0.35), rgba(212,175,55,0.08));
  border: 1px solid rgba(212,175,55,0.5); border-radius: 50%;
  filter: drop-shadow(0 0 10px rgba(212,175,55,0.4));
}
.level-name { font-family: var(--serif); font-size: 1.15rem; color: var(--gold-soft); }
.level-xp { font-size: 0.85rem; color: var(--muted); }
.xp-bar {
  height: 12px; border-radius: 999px; margin: 12px 0 6px;
  background: rgba(212,175,55,0.12); border: 1px solid rgba(212,175,55,0.25);
  overflow: hidden;
}
.xp-bar > div {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  border-radius: 999px; transition: width 0.6s ease;
  box-shadow: 0 0 12px rgba(212,175,55,0.6);
}
.xp-bar.big { height: 16px; }
.level-next { font-size: 0.82rem; margin-top: 4px; }
.level-tier { margin-top: 10px; font-size: 0.9rem; }
.levels-list { margin-top: 12px; border-top: 1px solid rgba(212,175,55,0.15); padding-top: 8px; }
.lvl-row {
  display: flex; justify-content: space-between; padding: 5px 2px;
  font-size: 0.85rem; color: var(--muted);
}
.lvl-row.reached { color: var(--text); }
.lvl-row.current { color: var(--gold-soft); font-weight: 700; }

.tier-card { border-color: rgba(123,92,255,0.4); }

/* Liga semanal */
.week-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.85rem; }
.week-key { min-width: 86px; color: var(--muted); }
.week-bar { flex: 1; height: 10px; border-radius: 999px; background: rgba(123,92,255,0.12); overflow: hidden; }
.week-bar > div { height: 100%; background: linear-gradient(90deg, var(--violet), #a78bfa); border-radius: 999px; }
.week-xp { min-width: 52px; text-align: right; color: var(--gold-soft); font-weight: 600; }

/* Insignias */
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ach {
  border-radius: var(--radius); padding: 12px 8px; text-align: center;
  border: 1px solid rgba(212,175,55,0.18);
  background: linear-gradient(160deg, var(--night-2), var(--night-3));
}
.ach-icon { font-size: 2rem; }
.ach-name { font-family: var(--serif); font-size: 0.85rem; margin: 6px 0 2px; color: var(--gold-soft); }
.ach-hint { font-size: 0.68rem; color: var(--muted); line-height: 1.35; min-height: 2.6em; }
.ach.unlocked { border-color: var(--gold); box-shadow: 0 0 16px rgba(212,175,55,0.35); }
.ach.unlocked .ach-icon { filter: drop-shadow(0 0 8px rgba(212,175,55,0.7)); animation: ach-pop 0.5s ease; }
.ach.locked { opacity: 0.55; }
.ach.locked .ach-icon { filter: grayscale(1); }
@keyframes ach-pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Modal de celebración */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 6, 12, 0.82); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: linear-gradient(160deg, var(--night-2), var(--night-3));
  border: 2px solid var(--gold); border-radius: 22px;
  padding: 28px 24px; text-align: center; max-width: 340px; width: 100%;
  box-shadow: 0 0 60px rgba(212,175,55,0.45);
  animation: modal-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.7) translateY(20px); } }
.celebrate-emoji { font-size: 4rem; animation: ach-pop 0.6s ease; filter: drop-shadow(0 0 18px rgba(212,175,55,0.8)); }
.modal-box h2 { font-family: var(--serif); font-weight: normal; color: var(--gold-soft); margin: 10px 0 4px; }
.celebrate-name { font-family: var(--serif); font-size: 1.3rem; color: var(--gold); margin: 6px 0; }

/* ---------- Desktop ---------- */
@media (min-width: 640px) {
  .view h1 { font-size: 2rem; }
  .ring-wrap { width: 250px; height: 250px; }
}

/* ---------- Compat/i18n: añadidos v2 ---------- */
.header-actions { display: flex; align-items: center; gap: 8px; }
.btn-lang {
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.45);
  color: var(--gold-soft);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-lang:active { transform: scale(0.96); }
/* Banner de error amable (manejador global): oculto salvo fallo */
.errbar {
  position: sticky; top: 0; z-index: 60;
  background: #3a2b00;
  color: #ffd97a;
  border-bottom: 1px solid rgba(212, 175, 55, 0.5);
  padding: 10px 16px;
  font-size: 0.85rem;
  text-align: center;
}
/* Diagnóstico */
.diag-card { border-style: dashed; }
.diag-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.diag-row { display: flex; gap: 10px; align-items: flex-start; font-size: 0.88rem; }
.diag-ok { font-weight: 800; width: 20px; text-align: center; }
.diag-ok.ok { color: #7dff9e; }
.diag-ok.no { color: #ff8a8a; }
.diag-detail { word-break: break-word; font-size: 0.78rem; }
.diag-errors { font-size: 0.8rem; }
.diag-errors div { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
