@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&display=swap');

:root {
  --green: #58cc02;
  --green-dark: #46a302;
  --green-tint: #d7ffb8;
  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --blue-tint: #ddf4ff;
  --orange: #ff9600;
  --orange-dark: #e08600;
  --purple: #ce82ff;
  --purple-dark: #a568d1;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-tint: #ffdfe0;
  --yellow: #ffc800;
  --bg: #ffffff;
  --panel: #f7f7f7;
  --card: #ffffff;
  --ink: #4b4b4b;
  --ink-strong: #3c3c3c;
  --muted: #afafaf;
  --border: #e5e5e5;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--panel);
  color: var(--ink);
  font-family: "Baloo 2", -apple-system, "Segoe UI Rounded", "Segoe UI", Verdana, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}

button { font-family: inherit; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(0,0,0,0.06);
}

.screen { display: none; flex-direction: column; flex: 1; min-height: 100%; }
.screen.active { display: flex; }

/* ---------- BOTONES ---------- */
.btn {
  border: none;
  border-radius: 16px;
  padding: 15px 20px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
  text-transform: uppercase;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.btn-green { background: var(--green); box-shadow: 0 4px 0 var(--green-dark); }
.btn-blue { background: var(--blue); box-shadow: 0 4px 0 var(--blue-dark); }
.btn-orange { background: var(--orange); box-shadow: 0 4px 0 var(--orange-dark); }
.btn-purple { background: var(--purple); box-shadow: 0 4px 0 var(--purple-dark); }
.btn-red { background: var(--red); box-shadow: 0 4px 0 var(--red-dark); }
.btn-outline { background: #fff; color: var(--blue); border: 2px solid var(--border); box-shadow: 0 4px 0 var(--border); }
.btn:disabled { opacity: 1; cursor: default; background: #e5e5e5 !important; color: #afafaf !important; box-shadow: 0 4px 0 #d8d8d8 !important; }
.btn-wide { width: 100%; }

/* ---------- HOME ---------- */
#screen-home { align-items: center; justify-content: center; padding: 32px 24px; gap: 16px; text-align: center; background: #fff; }
.home-mascot { font-size: 84px; animation: float 2.4s ease-in-out infinite; }
@keyframes float { 0%,100%{transform: translateY(0);} 50%{transform: translateY(-10px);} }
.home-title { font-size: 28px; font-weight: 800; color: var(--green); margin: 0; }
.home-sub { color: var(--muted); font-size: 15px; margin: 0 0 6px; font-weight: 600; }
.home-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }
.best-score { background: var(--panel); border-radius: 14px; padding: 10px 18px; font-weight: 800; color: var(--orange-dark); border: 2px solid var(--border); }
.topics-list { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin-top: 6px; }
.topic-pill { background: var(--panel); border: 2px solid var(--border); border-radius: 20px; padding: 6px 12px; font-size: 12px; font-weight:700; color: var(--ink); }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px; background: #fff;
  position: sticky; top: 0; z-index: 5;
  border-bottom: 2px solid var(--border);
}
.topbar .close-btn { font-size: 24px; color: #ccc; background: none; border: none; cursor: pointer; font-weight: 700; padding: 4px; }
.progress-track { flex: 1; height: 16px; background: var(--border); border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--green); border-radius: 8px; transition: width 0.3s; }
.hud-stat { display: flex; align-items: center; gap: 4px; font-weight: 800; font-size: 16px; white-space: nowrap; }
.hearts { color: var(--red); }
.score-badge { color: var(--orange-dark); }
.flag-chip { font-size: 20px; line-height: 1; }

/* ---------- FRANJA DE NIVEL (racha de aciertos) ---------- */
.nivel-strip {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; font-size: 12px; font-weight: 800; letter-spacing: 0.4px;
  color: #fff; text-transform: uppercase; transition: background-color 0.35s ease;
}
.nivel-strip .nv-streak { font-weight: 700; opacity: 0.85; text-transform: none; letter-spacing: 0; }
.nivel-pulse { animation: nivelPulse 0.5s ease; }
@keyframes nivelPulse { 0%{ transform: scaleY(1); } 40%{ transform: scaleY(1.35); } 100%{ transform: scaleY(1); } }

/* ---------- PATH MAP (skill tree, estilo clásico Duolingo) ---------- */
#path-scroll { flex: 1; overflow-y: auto; padding: 34px 10px 60px; background: #fff; }
.path-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.node-row { display: flex; width: 100%; margin: 10px 0; }

/* anillo de progreso alrededor del nodo, como los "skills" clásicos */
.node-ring {
  width: 92px; height: 92px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; position: relative;
  background: conic-gradient(var(--ring-color, var(--yellow)) calc(var(--ring-pct, 0) * 1%), var(--border) 0);
}
.node-ring.locked-ring { background: var(--border); }
.node-ring-gap {
  width: 80px; height: 80px; border-radius: 50%; background: #fff;
  display: flex; align-items: center; justify-content: center;
}
.node {
  width: 68px; height: 68px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; border: none; position: relative;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
  color: #fff; cursor: pointer; flex-shrink: 0;
}
.node.locked { background: #cfd6dd !important; box-shadow: 0 6px 0 #b9c1c9; cursor: default; color: #fff; }
.node.locked .node-icon { opacity: 0.6; filter: grayscale(1); }
.node.current { animation: pulse 1.5s ease-in-out infinite; cursor: pointer; }
@keyframes pulse { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.07);} }
.node.done { filter: saturate(0.9); }

.node-crown {
  position: absolute; bottom: -11px; left: 50%; transform: translateX(-50%);
  background: var(--yellow); color: #6b4e00; border: 3px solid #fff;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; box-shadow: 0 3px 0 #d9a900; z-index: 2;
}
.node-crown.locked-crown { background: #cfd6dd; color: #8b93a0; box-shadow: 0 3px 0 #b9c1c9; }

.tema-caption {
  margin-top: 22px; font-size: 11px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.3px; text-align: center;
}

/* ---------- QUESTION SCREEN ---------- */
.q-wrap { flex: 1; display: flex; flex-direction: column; padding: 20px 18px 0; overflow-y: auto; }
.q-tema-tag {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  background: var(--panel); padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 800;
  margin-bottom: 16px;
}
.q-prompt {
  font-size: 20px; font-weight: 800; line-height: 1.4; color: var(--ink-strong);
  white-space: pre-line; margin-bottom: 22px;
}
.exercise-dots { display: flex; gap: 6px; align-self: center; margin: 4px 0 18px; }
.exercise-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.exercise-dots span.on { background: var(--blue); }
.exercise-dots span.ok { background: var(--green); }
.exercise-dots span.bad { background: var(--red); }

.options { display: flex; flex-direction: column; gap: 12px; padding-bottom: 24px; }
.option {
  background: #fff; border: 2px solid var(--border); border-bottom-width: 4px; border-radius: 14px; padding: 14px 16px;
  font-size: 16px; font-weight: 700; text-align: left; cursor: pointer; display: flex;
  align-items: center; gap: 10px; color: var(--ink-strong); line-height: 1.35;
}
.option .mark {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); flex: 0 0 24px;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px; color: transparent;
}
.option.selected { background: var(--blue-tint); border-color: var(--blue); color: var(--blue-dark); }
.option.selected .mark { border-color: var(--blue); background: var(--blue); color: #fff; }
.option.correct { background: var(--green-tint); border-color: var(--green); color: var(--green-dark); }
.option.correct .mark { background: var(--green); border-color: var(--green); color:#fff; }
.option.correct .mark::after { content: "✓"; }
.option.wrong { background: var(--red-tint); border-color: var(--red); color: var(--red-dark); }
.option.wrong .mark { background: var(--red); border-color: var(--red); color:#fff; }
.option.wrong .mark::after { content: "✕"; }
.option.disabled { pointer-events: none; }
.option:active:not(.disabled) { transform: scale(0.985); }

@keyframes shake { 10%,90%{transform: translateX(-2px);} 20%,80%{transform: translateX(4px);} 30%,50%,70%{transform: translateX(-8px);} 40%,60%{transform: translateX(8px);} }
.shake { animation: shake 0.4s; }

.q-footer {
  padding: 14px 18px calc(14px + var(--safe-bottom));
  border-top: 2px solid var(--border); background: #fff;
}
.feedback-banner {
  display: none; align-items: center; gap: 12px; padding: 14px 18px calc(10px + var(--safe-bottom));
  font-weight: 800; font-size: 16px; border-top: 2px solid transparent;
}
.feedback-banner.show { display: flex; }
.feedback-banner.ok { background: var(--green-tint); color: var(--green-dark); }
.feedback-banner.bad { background: var(--red-tint); color: var(--red-dark); }
.feedback-banner .fb-icon {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff; flex-shrink: 0;
}
.feedback-banner.ok .fb-icon { background: var(--green); }
.feedback-banner.bad .fb-icon { background: var(--red); }

/* ---------- RESULT / FINISH / GAMEOVER ---------- */
.center-screen { align-items: center; justify-content: center; text-align: center; padding: 30px 24px; gap: 12px; flex: 1; background: #fff; }
.big-emoji { font-size: 72px; }
.result-title { font-size: 24px; font-weight: 800; margin: 0; color: var(--ink-strong); }
.score-ring {
  width: 150px; height: 150px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  flex-direction: column; background: conic-gradient(var(--green) calc(var(--pct,0) * 1%), var(--border) 0);
  margin: 8px 0;
}
.score-ring-inner {
  width: 122px; height: 122px; border-radius: 50%; background: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.score-ring-inner b { font-size: 32px; color: var(--ink-strong); }
.score-ring-inner span { font-size: 12px; color: var(--muted); font-weight: 700; }
.stars { font-size: 28px; letter-spacing: 4px; }

.stat-tiles { display: flex; gap: 10px; width: 100%; max-width: 360px; margin-top: 6px; }
.stat-tile {
  flex: 1; border: 2px solid var(--border); border-radius: 14px; padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat-tile .st-val { font-size: 19px; font-weight: 800; }
.stat-tile .st-label { font-size: 10px; font-weight: 800; text-transform: uppercase; color: var(--muted); letter-spacing: 0.3px; }
.stat-tile.st-green { border-color: var(--green); } .stat-tile.st-green .st-val { color: var(--green-dark); }
.stat-tile.st-red { border-color: var(--red); } .stat-tile.st-red .st-val { color: var(--red-dark); }
.stat-tile.st-blue { border-color: var(--blue); } .stat-tile.st-blue .st-val { color: var(--blue-dark); }

/* ---------- LEGENDARY ---------- */
.leg-list { display: flex; flex-direction: column; gap: 12px; padding: 18px; background: #fff; flex: 1; }
.leg-card {
  background: #fff; border-radius: 16px; padding: 16px; display: flex; align-items: center; gap: 14px;
  border: 2px solid var(--border); border-bottom-width: 4px; cursor: pointer; text-align: left;
}
.leg-card .emoji { font-size: 30px; }
.leg-card h3 { margin: 0 0 3px; font-size: 15px; color: var(--ink-strong); }
.leg-card p { margin: 0; font-size: 12px; color: var(--muted); font-weight: 600; }
.timer-bar-wrap { padding: 10px 18px; background: #fff; }
.timer-bar { height: 10px; border-radius: 6px; background: var(--border); overflow: hidden; }
.timer-bar-fill { height: 100%; background: var(--red); width: 100%; transition: width 1s linear; }

/* ---------- HEADER SIMPLE (menu screens) ---------- */
.simple-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: #fff; border-bottom: 2px solid var(--border); }
.simple-header h2 { flex: 1; font-size: 18px; margin: 0; color: var(--ink-strong); }
.icon-btn { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); font-weight: 700; }

.badge-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.badge-chip { background: var(--yellow); color: #6b4e00; padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 800; }

/* ---------- SweetAlert2 (tema Duolingo) ---------- */
.swal-kid-popup {
  font-family: "Baloo 2", -apple-system, "Segoe UI Rounded", sans-serif !important;
  border-radius: 20px !important;
}
.swal-kid-popup .swal2-title { font-weight: 800 !important; color: var(--ink-strong) !important; }
.swal-kid-btn {
  border-radius: 14px !important; font-weight: 800 !important; text-transform: uppercase !important;
  padding: 10px 22px !important; box-shadow: 0 4px 0 var(--green-dark) !important; font-size: 14px !important;
}
.swal-kid-btn-cancel {
  border-radius: 14px !important; font-weight: 800 !important; text-transform: uppercase !important;
  padding: 10px 22px !important; color: var(--ink) !important; box-shadow: 0 4px 0 #cfcfcf !important; font-size: 14px !important;
}

@media (max-width: 380px) {
  .node { width: 58px; height: 58px; font-size: 24px; }
  .q-prompt { font-size: 18px; }
}
