:root {
  --fundo: #f6f5f2;
  --cartao: #ffffff;
  --texto: #1d1d1b;
  --sub: #6b6a66;
  --borda: #e3e1dc;
  --primaria: #2f5bea;
  --primaria-texto: #ffffff;
  --ok: #1f8a4c;
  --ok-fundo: #e6f4ec;
  --alerta: #c2410c;
  --alerta-fundo: #fdeee5;
  --atras: #b7791f;
  --codigo: #1e1e24;
  --codigo-texto: #e8e8ec;
  --sombra: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .04);
  --raio: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #141413;
    --cartao: #1f1f1d;
    --texto: #ecebe7;
    --sub: #9d9b95;
    --borda: #33322f;
    --primaria: #6f8cff;
    --primaria-texto: #0d0d0c;
    --ok: #4cc584;
    --ok-fundo: #18321f;
    --alerta: #ff9a62;
    --alerta-fundo: #3a2214;
    --atras: #e0b155;
    --codigo: #0d0d10;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
a { color: var(--primaria); }
.sub { color: var(--sub); font-size: .875rem; }
.erro { color: var(--alerta); min-height: 1.2em; }

/* ---------- controles ---------- */
button, .botao {
  font: inherit; font-size: .9rem;
  display: inline-flex; align-items: center; gap: .35em;
  padding: .5em .9em; border-radius: 8px;
  border: 1px solid var(--borda); background: var(--cartao); color: var(--texto);
  cursor: pointer; text-decoration: none;
}
button:hover:not(:disabled), .botao:hover { border-color: var(--primaria); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primaria); outline-offset: 2px;
}
.primario { background: var(--primaria); color: var(--primaria-texto); border-color: var(--primaria); }
.perigo { color: var(--alerta); }
.link { background: none; border: none; padding: .2em 0; color: var(--primaria); }
.grande { padding: .75em 1.2em; font-size: 1rem; font-weight: 600; }
.marcado { border-color: var(--primaria); background: color-mix(in srgb, var(--primaria) 14%, var(--cartao)); }
.marcado.ok { border-color: var(--ok); background: var(--ok-fundo); color: var(--ok); }
.marcado.travei { border-color: var(--alerta); background: var(--alerta-fundo); color: var(--alerta); }
input, textarea, select {
  font: inherit; width: 100%; padding: .6em .75em; border-radius: 8px;
  border: 1px solid var(--borda); background: var(--fundo); color: var(--texto);
}
textarea { resize: vertical; }
input[type=checkbox] { width: auto; }
input.curto { width: 5em; }
label { display: inline-flex; align-items: center; gap: .4em; }
form > * + * { margin-top: .6rem; }
form label:has(select) { display: flex; flex-direction: column; align-items: stretch; }
details summary { cursor: pointer; padding: .25em 0; }

.linha { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.linha.entre { justify-content: space-between; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1.1rem 1.25rem; box-shadow: var(--sombra); }
.caixa { border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; margin: 1rem 0; background: var(--cartao); }
.estreito { width: min(440px, 100%); }
.tela-central { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.lista { list-style: none; padding: 0; margin: 0; }
.lista li { padding: .5rem 0; border-bottom: 1px solid var(--borda); display: flex; flex-direction: column; }
.lista li.linha { flex-direction: row; }
.vazio { color: var(--sub); text-align: center; padding: 4rem 1rem; }
.dica { color: var(--sub); margin: .5rem 0 0; }

.topo {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .75rem 16px; background: var(--cartao); border-bottom: 1px solid var(--borda);
  position: sticky; top: 0; z-index: 5;
}
.topo h1 { margin: 0; }
.ritmo { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.ritmo button { padding: .35em .7em; }

/* ---------- aluno ---------- */
.corpo { display: grid; grid-template-columns: 260px 1fr; max-width: 1180px; margin: 0 auto; }
.lista-partes {
  display: flex; flex-direction: column; gap: 2px; padding: 1rem .75rem;
  position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 64px); overflow-y: auto;
}
.item-parte { justify-content: flex-start; text-align: left; border-color: transparent; background: none; width: 100%; }
.item-parte.ativa { background: var(--cartao); border-color: var(--borda); font-weight: 600; }
.item-parte .icone { width: 1.4em; flex: none; text-align: center; }
main { padding: 1.25rem 16px 4rem; min-width: 0; }
#parte { max-width: 760px; }
#parteTitulo { font-size: 1.5rem; }

.conteudo pre {
  position: relative; background: var(--codigo); color: var(--codigo-texto);
  padding: 1rem 1rem; padding-right: 6.5rem; border-radius: 10px; overflow-x: auto; font-size: .9rem;
}
.conteudo code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.conteudo :not(pre) > code { background: color-mix(in srgb, var(--texto) 8%, transparent); padding: .1em .35em; border-radius: 4px; }
.conteudo img { max-width: 100%; }
.copiar {
  position: absolute; top: .5rem; right: .5rem; font-size: .8rem; padding: .25em .6em;
  background: rgba(255, 255, 255, .1); color: var(--codigo-texto); border-color: rgba(255, 255, 255, .2);
}
.acoes { margin: 1.5rem 0; }

.duvida { display: flex; gap: .75rem; padding: .75rem 0; border-top: 1px solid var(--borda); }
.duvida.respondida { opacity: .65; }
.duvida-corpo { flex: 1; min-width: 0; }
.duvida-corpo > small { display: block; }
.duvida .texto { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.voto { flex: none; align-self: flex-start; min-width: 3.2em; justify-content: center; font-variant-numeric: tabular-nums; }
span.voto { padding: .4em .5em; border: 1px solid var(--borda); border-radius: 8px; font-size: .9rem; }
.resposta { margin-top: .4rem; padding: .4rem .6rem; border-left: 3px solid var(--borda); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; }
.resposta.prof { border-color: var(--primaria); }
.respondendo { display: flex; justify-content: space-between; gap: .5rem; font-size: .875rem; color: var(--sub); }
.respondendo em { overflow-wrap: anywhere; }

.leitura #ritmo, .leitura #acoes, .leitura #checkpoint, .leitura #formDuvida, .leitura [data-acao=responder] { display: none !important; }
.leitura .voto { pointer-events: none; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.quiz { width: min(520px, 100%); }
.quiz-topo { display: flex; justify-content: space-between; color: var(--sub); font-size: .875rem; margin-bottom: .5rem; font-variant-numeric: tabular-nums; }
.opcoes { display: grid; gap: .5rem; margin: 1rem 0 .5rem; }
.opcao { justify-content: space-between; width: 100%; text-align: left; padding: .8em 1em; font-size: 1rem; }
.opcao:disabled { opacity: 1; }
.opcao.escolhida { border-color: var(--primaria); border-width: 2px; }
.opcao.certa { border-color: var(--ok); background: var(--ok-fundo); }
.opcao.errada { border-color: var(--alerta); background: var(--alerta-fundo); }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 30; width: min(480px, calc(100% - 32px)); }
.toast { background: var(--texto); color: var(--fundo); padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--sombra); animation: entra .2s ease-out; }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- barras ---------- */
.barra { flex: 1; height: 10px; background: var(--borda); border-radius: 99px; overflow: hidden; min-width: 60px; }
.barra i { display: block; height: 100%; background: var(--primaria); border-radius: 99px; transition: width .3s; }
.barra-opcao { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(60px, 1fr) 2.5em; align-items: center; gap: .6rem; padding: .3rem 0; }
.barra-opcao b { text-align: right; font-variant-numeric: tabular-nums; }
.barra-opcao.certa .barra i { background: var(--ok); }

/* ---------- professor ---------- */
.prof .grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; padding: 1rem 16px 4rem; max-width: 1400px; margin: 0 auto; }
.destaque { grid-column: 1 / -1; }
.destaque h2 { font-size: 1.5rem; }
.contadores { display: flex; flex-wrap: wrap; gap: 1rem; margin: .5rem 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.contadores .ok { color: var(--ok); }
.contadores .travei { color: var(--alerta); }
.destaque .barra { height: 14px; margin: .5rem 0; }
.destaque .barra i { background: var(--ok); }
.travados { color: var(--alerta); }
.liberar { margin-top: .75rem; width: 100%; justify-content: center; }
.link-box { display: flex; gap: 1rem; align-items: center; margin: 1rem 16px; flex-wrap: wrap; }
.link-box img { width: 160px; height: 160px; background: #fff; border-radius: 8px; }
.link-box > div { flex: 1; min-width: 220px; display: grid; gap: .5rem; }
.mapa-item summary { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(60px, 1fr) 2em; gap: .6rem; align-items: center; list-style: none; }
.mapa-item summary::-webkit-details-marker { display: none; }
.mapa-item summary b { text-align: right; }
.mapa-item.bloqueada { opacity: .45; }
.mapa-item.atras summary span { color: var(--atras); font-weight: 600; }
.mapa-item.atras .barra i { background: var(--atras); }
.prints { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.prints figure { margin: 0; }
.prints img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--borda); }
.prints figcaption { font-size: .8rem; color: var(--sub); margin: .25rem 0; }

/* ---------- celular ---------- */
@media (max-width: 760px) {
  .corpo { grid-template-columns: 1fr; }
  .lista-partes {
    flex-direction: row; overflow-x: auto; position: sticky; top: 0; z-index: 4; max-height: none;
    background: var(--fundo); border-bottom: 1px solid var(--borda); padding: .5rem 16px;
  }
  .item-parte { width: auto; white-space: nowrap; }
  .topo { position: static; }
  .prof .grade { grid-template-columns: 1fr; }
  .conteudo pre { padding-right: 1rem; padding-top: 2.5rem; }
}
