:root {
  --navy-950: #0A1020;
  --navy-900: #0F1B35;
  --navy-800: #16254A;
  --navy-700: #1B2C55;
  --blue-700: #1D4ED8;
  --blue-500: #3B82F6;
  --blue-400: #60A5FA;
  --blue-300: #93C5FD;
  --ink-100: #E6ECFF;
  --ink-300: #B8C3E0;
  --ink-500: #7C89AD;
  --green: #34D399;
  --green-dark: #065F46;
  --red: #F87171;
  --red-dark: #7F1D1D;
  --gold: #FBBF24;
  --radius: 20px;
  --nav-h: 68px;
}

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

html { height: 100%; }

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--navy-950);
  color: var(--ink-100);
  min-height: 100%;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; border: none; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ===== Header ===== */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 2px 10px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--navy-950) 78%, transparent);
}
.topbar img.logo { width: 40px; height: 40px; border-radius: 11px; }
.topbar .brand { font-weight: 900; font-size: 20px; letter-spacing: -0.3px; }
.topbar .brand span { color: var(--blue-400); }
.topbar .spacer { flex: 1; }
.stat-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--navy-800); border-radius: 999px;
  padding: 6px 12px; font-weight: 800; font-size: 14px;
  border: 1.5px solid var(--navy-700);
}
.stat-chip.xp { color: var(--blue-300); }
.stat-chip.streak { color: var(--gold); }

.hero-sub { color: var(--ink-300); font-size: 15px; padding: 2px 4px 18px; }

/* ===== Chapter cards ===== */
.chapter {
  background: var(--navy-900);
  border: 1.5px solid var(--navy-700);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  margin-bottom: 16px;
}
.chapter-head { display: flex; align-items: center; gap: 12px; }
.chapter-emoji {
  width: 52px; height: 52px; flex: none;
  display: grid; place-items: center;
  font-size: 27px;
  background: linear-gradient(135deg, var(--navy-800), var(--navy-700));
  border-radius: 16px;
  border: 1.5px solid rgba(59, 130, 246, .35);
}
.chapter-title { font-size: 17px; font-weight: 900; }
.chapter-desc { font-size: 13.5px; color: var(--ink-300); margin-top: 1px; }
.chapter-progress {
  height: 8px; background: var(--navy-800); border-radius: 99px;
  margin: 14px 0 4px; overflow: hidden;
}
.chapter-progress i {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--blue-700), var(--blue-400));
  transition: width .4s ease;
}
.chapter-progress-label { font-size: 12px; color: var(--ink-500); font-weight: 700; margin-bottom: 10px; }

.lessons { display: flex; flex-wrap: wrap; gap: 10px; }
.lesson-node {
  flex: 1 1 calc(50% - 5px);
  min-width: 150px;
  display: flex; align-items: center; gap: 10px;
  background: var(--navy-800);
  border: 1.5px solid var(--navy-700);
  border-radius: 15px;
  padding: 11px 12px;
  color: var(--ink-100);
  font-size: 13.5px; font-weight: 800;
  text-align: left;
  transition: transform .12s ease, border-color .12s ease;
}
.lesson-node:active { transform: scale(.97); }
.lesson-node .dot {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 16px;
  background: var(--navy-700);
}
.lesson-node.done { border-color: rgba(52, 211, 153, .45); }
.lesson-node.done .dot { background: rgba(52, 211, 153, .16); }
.lesson-node.current { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
.lesson-node.current .dot { background: var(--blue-700); animation: pulse 1.8s infinite; }
.lesson-node.locked { opacity: .45; }
.lesson-node.locked .dot { filter: grayscale(1); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, .5); }
  60% { box-shadow: 0 0 0 9px rgba(59, 130, 246, 0); }
}

/* ===== Lesson screen ===== */
.lesson-top {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 2px 14px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--navy-950) 80%, transparent);
}
.btn-quit {
  background: none; color: var(--ink-500);
  font-size: 26px; font-weight: 700; line-height: 1;
  padding: 4px 8px;
}
.qbar { flex: 1; height: 14px; background: var(--navy-800); border-radius: 99px; overflow: hidden; }
.qbar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--blue-700), var(--blue-400));
  border-radius: 99px;
  transition: width .35s ease;
}

.q-count { font-size: 13px; font-weight: 800; color: var(--ink-500); padding: 0 4px 6px; }
.q-text { font-size: 21px; font-weight: 900; padding: 4px 4px 20px; line-height: 1.35; }
.q-retry-tag {
  display: inline-block; background: rgba(251, 191, 36, .14); color: var(--gold);
  border-radius: 8px; padding: 2px 9px; font-size: 12px; font-weight: 800; margin-bottom: 10px;
}

.choices { display: flex; flex-direction: column; gap: 11px; }
.choice {
  background: var(--navy-900);
  border: 2px solid var(--navy-700);
  border-radius: 15px;
  padding: 15px 16px;
  color: var(--ink-100);
  font-size: 16px; font-weight: 700;
  text-align: left;
  transition: transform .1s ease, border-color .12s ease, background .12s ease;
}
.choice:active { transform: scale(.98); }
.choice.selected { border-color: var(--blue-500); background: rgba(59, 130, 246, .12); }
.choice.correct { border-color: var(--green); background: rgba(52, 211, 153, .13); }
.choice.wrong { border-color: var(--red); background: rgba(248, 113, 113, .12); }
.choice:disabled { cursor: default; }
.choice code, .q-text code, .fb-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--navy-800); border-radius: 6px; padding: 1px 6px; font-size: .93em;
  color: var(--blue-300);
}

.tf-row { display: flex; gap: 12px; }
.tf-row .choice { flex: 1; text-align: center; font-size: 17px; font-weight: 900; }

.type-input {
  width: 100%;
  background: var(--navy-900);
  border: 2px solid var(--navy-700);
  border-radius: 15px;
  padding: 16px;
  color: var(--ink-100);
  font-size: 17px; font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  outline: none;
}
.type-input:focus { border-color: var(--blue-500); }
.type-input.correct { border-color: var(--green); }
.type-input.wrong { border-color: var(--red); }

.btn-main {
  width: 100%;
  margin-top: 22px;
  background: linear-gradient(180deg, var(--blue-500), var(--blue-700));
  color: #fff;
  font-size: 17px; font-weight: 900; letter-spacing: .2px;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 0 #16389B;
  transition: transform .1s ease, opacity .15s ease;
}
.btn-main:active { transform: translateY(2px); box-shadow: 0 2px 0 #16389B; }
.btn-main:disabled { opacity: .4; box-shadow: none; cursor: default; }
.btn-ghost {
  width: 100%; margin-top: 12px;
  background: none; border: 2px solid var(--navy-700);
  color: var(--ink-300); font-size: 15px; font-weight: 800;
  border-radius: 16px; padding: 13px;
}

/* feedback sheet */
.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .25s ease;
}
.feedback .inner { max-width: 560px; margin: 0 auto; }
.feedback.good { background: var(--green-dark); }
.feedback.bad { background: var(--red-dark); }
.fb-title { font-size: 19px; font-weight: 900; display: flex; align-items: center; gap: 8px; }
.feedback.good .fb-title { color: var(--green); }
.feedback.bad .fb-title { color: var(--red); }
.fb-text { font-size: 14.5px; margin-top: 5px; color: var(--ink-100); }
.feedback .btn-main { margin-top: 14px; }
.feedback.good .btn-main { background: var(--green); color: #04291C; box-shadow: 0 4px 0 #0B7A55; }
.feedback.bad .btn-main { background: var(--red); color: #3D0808; box-shadow: 0 4px 0 #B33A3A; }

@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Intro cards (uitleg vooraf) ===== */
.intro-card {
  background: var(--navy-900);
  border: 1.5px solid var(--navy-700);
  border-radius: var(--radius);
  padding: 30px 22px 24px;
  text-align: center;
  margin-top: 6px;
}
.intro-card .big-emoji { font-size: 58px; line-height: 1; }
.intro-card h2 { font-size: 22px; font-weight: 900; margin: 14px 0 10px; }
.intro-card p {
  font-size: 16.5px; color: var(--ink-100);
  text-align: left; line-height: 1.65;
}
.intro-dots { display: flex; gap: 7px; justify-content: center; margin-top: 20px; }
.intro-dots i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--navy-700);
}
.intro-dots i.on { background: var(--blue-400); }

/* ===== Lesson result ===== */
.result { text-align: center; padding-top: 8vh; }
.result .big { font-size: 74px; }
.result h2 { font-size: 26px; font-weight: 900; margin: 10px 0 6px; }
.result p { color: var(--ink-300); }
.result-stats { display: flex; gap: 12px; justify-content: center; margin: 26px 0; }
.result-stat {
  background: var(--navy-900); border: 1.5px solid var(--navy-700);
  border-radius: 16px; padding: 14px 20px; min-width: 108px;
}
.result-stat .val { font-size: 24px; font-weight: 900; color: var(--blue-300); }
.result-stat .lbl { font-size: 12px; font-weight: 800; color: var(--ink-500); text-transform: uppercase; letter-spacing: .5px; }
.result-stat.gold .val { color: var(--gold); }
.result-stat.green .val { color: var(--green); }

/* ===== Cheatsheet ===== */
.sheet-section { margin-bottom: 22px; }
.sheet-section h3 {
  font-size: 15px; font-weight: 900; color: var(--blue-300);
  display: flex; align-items: center; gap: 8px;
  padding: 0 2px 10px;
}
.cmd-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--navy-900); border: 1.5px solid var(--navy-700);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 9px;
}
.cmd-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13.5px; font-weight: 600; color: var(--blue-300);
  flex: none; max-width: 46%; overflow-wrap: break-word;
}
.cmd-row .what { font-size: 13px; color: var(--ink-300); flex: 1; }
.cmd-row .copy {
  background: var(--navy-800); color: var(--ink-300);
  border-radius: 9px; padding: 6px 9px; font-size: 12px; flex: none;
}

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%;
  transform: translateX(-50%);
  background: var(--blue-700); color: #fff;
  font-weight: 800; font-size: 14px;
  padding: 10px 18px; border-radius: 99px; z-index: 60;
  animation: slideup .2s ease;
}

/* ===== Profile ===== */
.profile-hero { text-align: center; padding: 22px 0 6px; }
.profile-hero img { width: 92px; height: 92px; border-radius: 26px; }
.profile-hero h2 { font-size: 22px; font-weight: 900; margin-top: 12px; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.pcard {
  background: var(--navy-900); border: 1.5px solid var(--navy-700);
  border-radius: 16px; padding: 16px; text-align: center;
}
.pcard .val { font-size: 26px; font-weight: 900; color: var(--blue-300); }
.pcard .lbl { font-size: 12px; font-weight: 800; color: var(--ink-500); }
.section-title { font-size: 15px; font-weight: 900; color: var(--blue-300); margin: 22px 0 10px; }
.info-card {
  background: var(--navy-900); border: 1.5px solid var(--navy-700);
  border-radius: 16px; padding: 16px; font-size: 14px; color: var(--ink-300);
  margin-bottom: 12px;
}
.info-card b { color: var(--ink-100); }
.btn-danger {
  width: 100%; background: none; border: 2px solid var(--red-dark);
  color: var(--red); font-weight: 800; font-size: 14px;
  border-radius: 14px; padding: 12px; margin-top: 10px;
}

/* ===== Bottom nav ===== */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(15, 27, 53, .92);
  backdrop-filter: blur(14px);
  border-top: 1.5px solid var(--navy-700);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .inner {
  max-width: 560px; margin: 0 auto;
  display: flex; height: var(--nav-h);
}
.navbtn {
  flex: 1; background: none; color: var(--ink-500);
  font-size: 11.5px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.navbtn .ico { font-size: 22px; }
.navbtn.active { color: var(--blue-400); }

/* ===== Confetti ===== */
.confetti {
  position: fixed; top: -14px; z-index: 80;
  width: 10px; height: 15px; border-radius: 3px;
  animation: fall linear forwards;
  pointer-events: none;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: .9; }
}

.fade-in { animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (min-width: 561px) {
  .lesson-node { flex-basis: calc(50% - 5px); }
}
