*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-m); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: var(--fs-l); font-weight: 700; }
h3 { font-size: var(--fs-m); font-weight: 700; }
p { margin: 0; }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-s); }
.xs { font-size: var(--fs-xs); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Topbar / navegação ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--max); height: 100%; margin: 0 auto; padding: 0 var(--gutter);
  display: flex; align-items: center; gap: 24px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; color: var(--brand); }
.logo svg { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: var(--radius-s);
  font-size: var(--fs-s); font-weight: 600; color: var(--text-2);
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--brand); }
.nav svg { width: 20px; height: 20px; }
.tabbar { display: none; }

@media (max-width: 720px) {
  .topbar .nav { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 11px; font-weight: 600; color: var(--text-2);
  }
  .tabbar a.active { color: var(--brand); }
  .tabbar svg { width: 22px; height: 22px; }
  main { padding-bottom: calc(var(--tabbar-h) + 24px) !important; }
}
body.focus .topbar, body.focus .tabbar { display: none; }
body.focus main { padding-bottom: 0 !important; }

main { max-width: var(--max); margin: 0 auto; padding: 24px var(--gutter) 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-link { display: block; transition: border-color .15s, transform .15s; }
.card-link:hover { border-color: var(--brand); }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; font-size: var(--fs-s); cursor: pointer; user-select: none;
  background: var(--brand); color: var(--on-brand); transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--brand-strong); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ok { background: var(--ok); } .btn-ok:hover { background: var(--ok); filter: brightness(1.05); }
.btn-err { background: var(--err); } .btn-err:hover { background: var(--err); filter: brightness(1.05); }
.btn-block { width: 100%; }
.btn-s { min-height: 34px; padding: 0 12px; font-size: var(--fs-xs); }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; }
.field label { font-size: var(--fs-s); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
textarea.input { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat .label { font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; }
.stat .value { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: var(--fs-s); font-weight: 600; color: var(--text-2); margin-left: 2px; }
.stat-inline { display: flex; gap: 24px; flex-wrap: wrap; }
.stat-inline .value { font-size: var(--fs-l); }

/* ---------- Barra de progresso ---------- */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .3s; }
.bar.ok > span { background: var(--ok); }

/* ---------- Gráfico semanal ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 120px; }
.week .col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week .b { width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--brand); min-height: 2px; }
.week .b.zero { background: var(--border); }
.week .d { font-size: 11px; color: var(--text-2); font-weight: 600; text-transform: uppercase; }
.week .col.today .d { color: var(--brand); }

/* ---------- Trilhas ---------- */
.track { display: flex; gap: 14px; align-items: center; }
.track-icon {
  flex: none; width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  font-size: 24px; background: var(--brand-soft);
}
.track-body { flex: 1; min-width: 0; display: grid; gap: 6px; }
.track-meta { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.err { background: var(--err-soft); color: var(--err); }

/* ---------- Caminho de lições ---------- */
.unit { padding: 4px 0 8px; }
.unit-head { display: flex; align-items: baseline; gap: 10px; margin: 18px 0 10px; }
.unit-num { font-size: var(--fs-xs); font-weight: 800; color: var(--brand); letter-spacing: .06em; text-transform: uppercase; }
.lesson {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.lesson + .lesson { margin-top: 8px; }
.lesson:hover { border-color: var(--brand); }
.node {
  flex: none; width: 40px; height: 40px; border-radius: 999px; display: grid; place-items: center;
  font-weight: 800; border: 2px solid var(--border); color: var(--text-3); background: var(--surface);
}
.node svg { width: 20px; height: 20px; }
.lesson.done .node { background: var(--ok); border-color: var(--ok); color: #fff; }
.lesson.current .node { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 0 0 4px var(--brand-soft); }
.lesson.locked { opacity: .6; }
.lesson.empty { cursor: default; opacity: .5; }
.lesson.empty:hover { border-color: var(--border); }

/* ---------- Player ---------- */
.player { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.player-top { display: flex; align-items: center; gap: 12px; padding: 12px var(--gutter); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.player-top .bar { flex: 1; height: 10px; }
.player-top .count { font-size: var(--fs-s); font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.player-body { flex: 1; padding: 8px var(--gutter) 24px; display: grid; gap: 16px; align-content: start; }
.statement { font-size: 18px; font-weight: 600; line-height: 1.5; white-space: pre-wrap; }
.options { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: var(--radius); border: 2px solid var(--border); background: var(--surface);
  transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--text-3); }
.opt .letter {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 800; font-size: 13px; background: var(--surface-2); color: var(--text-2);
}
.opt .txt { padding-top: 3px; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .letter { background: var(--brand); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .letter { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--err); background: var(--err-soft); }
.opt.wrong .letter { background: var(--err); color: #fff; }
.opt:disabled { cursor: default; }
.player-foot {
  position: sticky; bottom: 0; padding: 14px var(--gutter) calc(14px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.player-foot.ok { background: var(--ok-soft); border-color: var(--ok); }
.player-foot.err { background: var(--err-soft); border-color: var(--err); }
.feedback { display: grid; gap: 6px; margin-bottom: 12px; }
.feedback strong { font-size: var(--fs-l); }
.player-foot.ok .feedback strong { color: var(--ok); }
.player-foot.err .feedback strong { color: var(--err); }
.feedback p { font-size: var(--fs-s); }

/* ---------- Resumo ---------- */
.summary-hero { text-align: center; padding: 32px 16px 16px; display: grid; gap: 8px; justify-items: center; }
.summary-hero .big { font-size: 56px; line-height: 1; }
.block-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.review-item { border-top: 1px solid var(--border); padding-top: 14px; display: grid; gap: 8px; }

/* ---------- Feed ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 700; font-size: var(--fs-s);
  color: var(--text-2); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); }
.activity-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 999px; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; background: var(--surface-2); color: var(--text-2);
}
.avatar.me { background: var(--brand); color: #fff; }
.activity-title { font-size: var(--fs-l); font-weight: 800; margin-bottom: 12px; letter-spacing: -.01em; }
.league-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.league-row:first-child { border-top: 0; }
.league-row .pos { width: 24px; text-align: center; font-weight: 800; color: var(--text-2); }
.league-row.me { color: var(--brand); }
.league-row .xp { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.auth .card { width: 100%; max-width: 400px; padding: 28px 24px; display: grid; gap: 18px; }
.auth .logo { font-size: 24px; justify-content: center; }

/* ---------- Toast / util ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: var(--radius);
  font-size: var(--fs-s); font-weight: 600; box-shadow: var(--shadow-l); max-width: calc(100% - 32px);
}
.toast.err { background: var(--err); color: #fff; }
.spinner { display: grid; place-items: center; padding: 64px 0; color: var(--text-2); }
.spinner::before {
  content: ""; width: 28px; height: 28px; border-radius: 999px;
  border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-2); display: grid; gap: 8px; justify-items: center; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.table td, .table th { padding: 8px 6px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: var(--fs-xs); color: var(--text-2); border-top: 0; }
.scroll-x { overflow-x: auto; }
h3 > svg, .btn > svg, .row > svg { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; flex: none; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.explain { white-space: pre-line; }
.feedback { max-height: 45vh; overflow-y: auto; }
