:root {
  --bg: #0f2419;
  --bg-2: #163525;
  --card: #fff8f0;
  --ink: #1d2b22;
  --muted: #5c6f64;
  --teal: #2a9d8f;
  --teal-d: #1d7a70;
  --gold: #e9c46a;
  --coral: #e76f51;
  --cream: #fff8f0;
  --line: rgba(255, 248, 240, 0.12);
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  --radius: 22px;
  --font: "Nunito", system-ui, sans-serif;
  --display: "Fredoka", "Nunito", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #245c3b 0%, transparent 50%),
    radial-gradient(900px 500px at 110% 10%, #3d2a12 0%, transparent 46%),
    var(--bg);
  color: var(--cream);
  min-height: 100%;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  padding-bottom: 88px;
}

.screen { display: none; animation: rise 0.35s ease; }
.screen.active { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  gap: 10px;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(var(--bg), transparent);
}
.stat {
  flex: 1;
  background: rgba(255, 248, 240, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
  text-align: center;
  font-weight: 800;
  font-size: 14px;
}
.stat.sm { flex: none; padding: 6px 10px; }

.hero {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 20px 12px;
}
.mascot {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: linear-gradient(160deg, #e9c46a, #e76f51);
  display: grid;
  place-items: center;
  font-size: 40px;
  box-shadow: var(--shadow);
  animation: bob 2.8s ease-in-out infinite;
}
.mascot.lg { width: 96px; height: 96px; font-size: 52px; margin: 0 auto 12px; }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.kicker {
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 12px;
}
h1, h2 { font-family: var(--display); }
h1 { font-size: 26px; line-height: 1.15; margin: 4px 0; }
.sub { color: #c9d8cf; font-size: 14px; }

.level-chip {
  margin: 0 20px 8px;
  display: inline-block;
  background: rgba(42, 157, 143, 0.2);
  border: 1px solid rgba(42, 157, 143, 0.45);
  color: #9ff3e6;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
}

.path { padding: 12px 20px 24px; }

.unit {
  margin-bottom: 28px;
}
.unit-head {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.unit-badge {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 26px;
  color: #fff;
  flex-shrink: 0;
}
.unit-head h3 { font-size: 18px; }
.unit-head p { color: var(--muted); font-size: 13px; font-weight: 700; }
.lock-note { margin-left: auto; font-size: 18px; }

.lessons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  position: relative;
}
.lessons::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 6px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,248,240,0.18) 0 10px,
    transparent 10px 18px
  );
  border-radius: 99px;
  z-index: 0;
}
.node {
  position: relative;
  z-index: 1;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 6px solid #0b1f14;
  display: grid;
  place-items: center;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 8px 0 #0b1f14, var(--shadow);
  transition: transform 0.12s ease;
}
.node:active { transform: translateY(4px); box-shadow: 0 4px 0 #0b1f14; }
.node.locked {
  background: #2c3d33;
  filter: grayscale(0.5);
  cursor: not-allowed;
  box-shadow: none;
}
.node.done { background: linear-gradient(160deg, #2a9d8f, #1d7a70); }
.node.ready { background: linear-gradient(160deg, #e9c46a, #f4a261); animation: pulse 1.8s infinite; }
.node .stars-mini { position: absolute; bottom: -8px; font-size: 11px; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.node-label {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: #d7e6dc;
  max-width: 140px;
}

.play-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 0;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,248,240,0.1);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.progress-wrap {
  flex: 1;
  height: 14px;
  background: rgba(255,248,240,0.12);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2a9d8f, #e9c46a);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.play-body { padding: 22px 20px 140px; }
.q-type {
  color: var(--gold);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.06em;
}
.q-prompt {
  font-size: 28px;
  margin: 8px 0 12px;
  line-height: 1.2;
}
.speak-btn, .btn {
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  border: 0;
}
.speak-btn {
  background: rgba(255,248,240,0.1);
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  margin-bottom: 10px;
}
.q-hint { color: #b7c9be; margin-bottom: 16px; min-height: 1.2em; }

.choices { display: grid; gap: 10px; }
.choice, .match-item, .letter {
  background: var(--card);
  color: var(--ink);
  border: 3px solid transparent;
  border-bottom-width: 6px;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 800;
  font-size: 17px;
  text-align: left;
  cursor: pointer;
}
.choice.selected, .match-item.selected { border-color: var(--teal); background: #e7f7f4; }
.choice.correct, .match-item.correct { border-color: #2a9d8f; background: #d8f3e8; }
.choice.wrong { border-color: var(--coral); background: #ffe3db; animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.letter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.letter {
  min-width: 44px;
  text-align: center;
  padding: 10px;
}
.typed {
  min-height: 56px;
  background: rgba(255,248,240,0.08);
  border: 2px dashed var(--line);
  border-radius: 16px;
  padding: 12px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}
.input-sw {
  width: 100%;
  padding: 14px 16px;
  border-radius: 16px;
  border: 3px solid #d9cbb8;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
}

.play-foot {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  bottom: 0;
  padding: 12px 16px 18px;
  background: linear-gradient(transparent, var(--bg) 28%);
}
.btn.primary {
  width: 100%;
  background: var(--teal);
  color: #fff;
  padding: 16px;
  border-radius: 16px;
  font-size: 18px;
  box-shadow: 0 6px 0 var(--teal-d);
}
.btn.primary:disabled { opacity: 0.45; box-shadow: none; }
.btn.primary:not(:disabled):active { transform: translateY(4px); box-shadow: 0 2px 0 var(--teal-d); }
.btn.ghost {
  width: 100%;
  background: transparent;
  color: #ffb4a2;
  border: 2px solid rgba(231, 111, 81, 0.4);
  padding: 14px;
  border-radius: 16px;
  margin-top: 16px;
}

.feedback {
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-weight: 800;
}
.feedback.ok { background: #d8f3e8; color: #146c5a; }
.feedback.bad { background: #ffe3db; color: #9b2c12; }

.result-card {
  margin: 48px 20px 0;
  background: var(--card);
  color: var(--ink);
  border-radius: 28px;
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.result-emoji { font-size: 64px; }
.stars { font-size: 32px; margin: 10px 0 18px; }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.result-stats div {
  background: #f3ece2;
  border-radius: 14px;
  padding: 10px 6px;
}
.result-stats strong { display: block; font-size: 20px; }
.result-stats span { font-size: 12px; color: var(--muted); font-weight: 800; }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #10261b;
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tab {
  background: none;
  border: 0;
  color: #8aa394;
  font-family: inherit;
  font-weight: 800;
  font-size: 11px;
  display: grid;
  gap: 2px;
  place-items: center;
  padding: 6px;
  cursor: pointer;
}
.tab.active { color: var(--gold); }
.tab span { font-size: 11px; }

.page-head { padding: 22px 20px 8px; }
.page-head p { color: #c9d8cf; }
.page-pad { padding: 8px 20px 24px; }

.badges-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.badge {
  background: rgba(255,248,240,0.08);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  text-align: center;
}
.badge.locked { opacity: 0.4; filter: grayscale(1); }
.badge .em { font-size: 32px; }
.badge h3 { font-size: 14px; margin: 6px 0 4px; }
.badge p { font-size: 12px; color: #b7c9be; }

.profile-card {
  background: var(--card);
  color: var(--ink);
  border-radius: 24px;
  padding: 20px;
  text-align: center;
}
#player-name {
  width: 100%;
  text-align: center;
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  border: 0;
  border-bottom: 3px dashed #d9cbb8;
  background: transparent;
  padding: 6px;
  margin-bottom: 8px;
}
.muted { color: var(--muted); font-weight: 700; }

.weak-card {
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
}
.weak-card small { color: var(--muted); display: block; }

.empty {
  text-align: center;
  padding: 40px 10px;
  color: #c9d8cf;
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}
.confetti i {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 16px;
  animation: fall 1.4s linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.2; }
}

.heart-break { animation: shake 0.4s ease; }
