:root {
  --bg: #eef6ff;
  --card-bg: #ffffff;
  --ink: #2b2d42;
  --ink-soft: #5b5f7a;
  --azul: #1cb0f6;
  --laranja: #ff9600;
  --verde: #58cc02;
  --verde-escuro: #3c9302;
  --vermelho: #ff4b4b;
  --dourado: #ffc800;
  --cinza: #b7b7c1;
  --radius: 18px;
  --font-title: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #eef6ff 0%, #f6faff 400px, #ffffff 900px);
  color: var(--ink);
  font-family: var(--font-body);
  overflow-x: hidden;
}

h1, h2 { font-family: var(--font-title); }

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

/* ---------------- Header ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #ffffffee;
  backdrop-filter: blur(6px);
  border-bottom: 2px solid #e3edf7;
}

.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  font-size: 1.05rem;
  font-family: var(--font-title);
  color: var(--ink);
  padding: 4px;
}
.brand-emoji { font-size: 1.6rem; }
.brand-text strong { color: var(--azul); }

.stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  border: none;
  background: #f1f6fc;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
}
.stat-xp { background: #fff3cf; color: #8a6d00; }
.stat-streak { background: #ffe4d6; color: #b64a00; }
.stat-rank { background: #e3f0ff; color: #0a5ba1; }
.stat-badges { background: #f1e7ff; color: #6a2fa8; }
.stat-reset { background: #f1f1f1; color: #888; padding: 6px 10px; }
.stat-reset:hover { background: #ffe0e0; color: var(--vermelho); }

.progress-outer {
  height: 6px;
  background: #e3edf7;
}
.progress-inner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--verde), var(--azul));
  transition: width .4s ease;
}

/* ---------------- Layout ---------------- */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 80px;
  min-height: 70vh;
}

.hero { text-align: center; margin: 20px 0 30px; }
.hero h1 { font-size: 1.9rem; margin-bottom: 8px; }
.hero p { color: var(--ink-soft); max-width: 560px; margin: 0 auto; line-height: 1.5; }

.btn-voltar {
  background: none;
  border: none;
  color: var(--azul);
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 16px;
  padding: 6px 0;
}
.btn-voltar:hover { text-decoration: underline; }

footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
  padding: 24px 16px 40px;
  max-width: 600px;
  margin: 0 auto;
}

/* ---------------- Trilha (mapa) ---------------- */

.trilha-path {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  padding: 10px 0 40px;
}

.materia-banner {
  --cor: #1cb0f6;
  align-self: stretch;
  text-align: center;
  background: var(--cor);
  color: white;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 10px;
  border-radius: 14px;
  margin: 24px 0 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}
.materia-icone { margin-right: 6px; }

.node {
  --cor: #1cb0f6;
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(100%, 480px);
  background: var(--card-bg);
  border: none;
  border-radius: 999px;
  padding: 10px 20px 10px 10px;
  box-shadow: 0 3px 0 #d9e4f0;
  text-align: left;
  transition: transform .15s ease;
}
.node-left { align-self: flex-start; margin-left: 0; }
.node-right { align-self: flex-end; margin-right: 0; }

.node-circulo {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: white;
  background: var(--cinza);
}

.node-titulo {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.95rem;
}

.node-atual {
  box-shadow: 0 4px 0 var(--cor);
  animation: pulse 1.8s infinite;
}
.node-atual .node-circulo { background: var(--cor); }

.node-completa .node-circulo { background: var(--verde); }
.node-completa { opacity: 0.85; }

.node-bloqueada { opacity: 0.55; cursor: not-allowed; }
.node-bloqueada .node-circulo { background: var(--cinza); }

.node:not(:disabled):hover { transform: scale(1.02); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--cor); }
  50% { box-shadow: 0 4px 0 var(--cor), 0 0 0 6px color-mix(in srgb, var(--cor) 25%, transparent); }
}

/* ---------------- Tópico ---------------- */

.topico-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 4px 20px rgba(20,40,80,0.06);
}

.topico-materia {
  display: inline-block;
  background: #f1f6fc;
  color: var(--azul);
  font-weight: 800;
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.topico-card h1 { font-size: 1.6rem; margin: 4px 0 12px; }

.topico-tip {
  background: #fffbe8;
  border-left: 4px solid var(--dourado);
  padding: 10px 14px;
  border-radius: 8px;
  color: #6b5400;
  line-height: 1.5;
  margin-bottom: 18px;
}

.video-wrap { margin-bottom: 12px; }
.video-frame {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
.video-frame iframe {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;
}
.video-credito { font-size: 0.78rem; color: var(--ink-soft); margin-top: 6px; }

.video-placeholder {
  background: #f6f8fb;
  border: 2px dashed #d5e0ee;
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
}

.btn-primario {
  display: inline-block;
  background: var(--verde);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 4px 0 var(--verde-escuro);
  width: 100%;
  margin: 6px 0 20px;
  transition: transform .1s ease;
}
.btn-primario:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--verde-escuro); }
.btn-primario:disabled { background: #cfd6e0; box-shadow: 0 4px 0 #b7bfcc; cursor: default; }

.btn-secundario {
  display: inline-block;
  margin-top: 10px;
  background: white;
  border: 2px solid var(--azul);
  color: var(--azul);
  font-weight: 800;
  padding: 8px 16px;
  border-radius: 12px;
  text-decoration: none;
}

.quiz-box { border-top: 2px dashed #e3edf7; padding-top: 18px; }
.quiz-box h2 { font-size: 1.2rem; margin-bottom: 12px; }

.pergunta { margin-bottom: 20px; }
.pergunta-texto { font-weight: 700; margin-bottom: 10px; }

.opcoes { display: flex; flex-direction: column; gap: 8px; }
.opcao {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid #e3edf7;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: border-color .15s ease, background .15s ease;
}
.opcao:hover { border-color: var(--azul); }
.opcao input { accent-color: var(--azul); width: 18px; height: 18px; }

.opcao-certa { border-color: var(--verde); background: #eafff0; }
.opcao-errada { border-color: var(--vermelho); background: #fff0f0; }

.pergunta-explicacao {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: #f6f8fb;
  padding: 8px 12px;
  border-radius: 10px;
}

.quiz-resultado {
  font-weight: 800;
  padding: 14px;
  border-radius: 12px;
  margin: 10px 0;
  text-align: center;
}
.resultado-bom { background: #eafff0; color: var(--verde-escuro); }
.resultado-ruim { background: #fff3e0; color: #a15c00; }

.btn-proximo { background: var(--azul); box-shadow: 0 4px 0 #0e86c4; }

/* ---------------- Conquistas ---------------- */

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.badge-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 18px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 0 #e3edf7;
}
.badge-locked { opacity: 0.5; filter: grayscale(1); }
.badge-emoji { font-size: 2rem; }
.badge-nome { font-weight: 800; font-size: 0.9rem; }
.badge-desc { font-size: 0.75rem; color: var(--ink-soft); }

/* ---------------- XP flash ---------------- */

.xp-flash {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translate(-50%, 0);
  background: var(--dourado);
  color: #6b5400;
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  opacity: 0;
  z-index: 100;
  transition: opacity .3s ease, transform .3s ease;
}
.xp-flash-go { opacity: 1; transform: translate(-50%, -14px); }

/* ---------------- Responsivo ---------------- */

@media (max-width: 640px) {
  .node { width: 100%; }
  .node-left, .node-right { align-self: center; }
  .hero h1 { font-size: 1.5rem; }
  .stats { justify-content: center; }
  .topbar-inner { justify-content: center; text-align: center; }
}
