/*
  Direção visual: "caderno de casa".
  Papel quente, tinta castanho-escura, um único acento (argila) e tipografia de livro para os títulos.
  Sem gradientes, sem sombras pesadas: a hierarquia faz-se com cor, tamanho e espaço.
  Contrastes de texto verificados (WCAG AA, mínimo 4,5:1). Ver docs/design.md.
*/

:root {
  /* Cores */
  --paper: #f6f1e8;      /* fundo */
  --card: #fffdf8;       /* superfícies */
  --ink: #23201b;        /* texto principal: 14,4:1 sobre o papel */
  --muted: #5e574c;      /* texto secundário: 6,3:1 sobre o papel */
  --line: #ddd4c4;       /* separadores decorativos */
  --edge: #8c8273;       /* contorno de controlos (limite de 3:1 para componentes) */
  --clay: #a23e1c;       /* ação principal: texto branco 6,5:1 */
  --clay-soft: #f3e3d9;
  --olive: #3b6b3a;      /* acerto */
  --olive-soft: #e6efdf;
  --red: #8e2424;        /* erro */
  --red-soft: #f7e3e0;
  --focus: #7a4f00;      /* anel de foco (3,5:1 sobre o papel) */
  --dark: #2b2620;       /* faixa do curso */

  /* Tipografia */
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Espaço (escala de 4 px) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;

  --radius: 12px;
  --radius-lg: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

/* Barra superior: só informação de progresso, em versaletes */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  gap: var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

#screen {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s6);
}

h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: var(--s2) 0 var(--s3);
}

h2.unit {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: var(--s6) 0 var(--s2);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
}

/* Botões */
.btn {
  font: inherit;
  font-weight: 600;
  min-height: 48px;
  border: 1.5px solid var(--edge);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--clay); border-color: var(--clay); color: #fff; }
.btn.primary:hover { background: #8a3216; border-color: #8a3216; }
.btn.back { border: none; background: none; font-size: 1.2rem; color: var(--muted); padding: var(--s1) var(--s2); min-height: 48px; }
.btn.opt { display: block; width: 100%; text-align: left; margin: var(--s2) 0; font-size: 1.05rem; font-weight: 500; }
.btn.opt.right { border: 2px solid var(--olive); background: var(--olive-soft); }
.btn.opt.wrong { border: 2px solid var(--red); background: var(--red-soft); }
.btn.play { margin-bottom: var(--s3); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { font-size: 0.95rem; margin-top: var(--s5); }

/* Cartão do curso: faixa escura, título em serifa */
.course-card {
  display: flex;
  gap: var(--s4);
  align-items: center;
  flex-wrap: wrap;
  padding: var(--s5);
  border-radius: var(--radius-lg);
  background: var(--dark);
  color: #fff;
  margin-bottom: var(--s5);
}
.course-card h1 { color: #fff; margin: 0; font-size: 1.6rem; }
.course-card p { margin: var(--s1) 0 0; color: #e9e2d4; }
.course-card .muted { color: #d6cdbd; }
.flag {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #fff;
}

/* Lições: linhas simples com separadores, sem cartões pesados */
.lesson-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  font: inherit;
  font-size: 1.05rem;
  text-align: left;
  padding: var(--s3) var(--s2);
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}
.lesson-row:hover { background: var(--card); }
.lesson-icon {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  font-size: 1.05rem;
  border-radius: 50%;
  background: var(--clay-soft);
}
.lesson-meta { margin-left: auto; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

/* Progresso: fio fino */
.progress {
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin: var(--s3) 0;
}
.progress .fill { height: 100%; background: var(--olive); transition: width 0.3s; }

.prompt { font-family: var(--serif); font-size: 1.4rem; line-height: 1.35; margin: var(--s2) 0 var(--s4); }

/* Escolhas (pílulas) */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 48px;
  padding: var(--s2) var(--s4);
  font: inherit;
  font-weight: 500;
  border: 1.5px solid var(--edge);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed='true'],
.chip.sel { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.chip.used { background: var(--clay-soft); border-color: var(--clay); }
.chip.done { background: var(--olive-soft); border-color: var(--olive); }
.chip.wrong { border-color: var(--red); background: var(--red-soft); animation: shake 0.4s; }
.chip:disabled { opacity: 0.55; cursor: default; }

.answer { min-height: 56px; padding: var(--s2) 0; border-bottom: 1px dashed var(--edge); margin-bottom: var(--s3); }
.bank { min-height: 50px; }
.col { display: inline-block; vertical-align: top; width: 48%; }

/* Retorno: barra lateral de cor, sem fundo cheio */
.feedback {
  margin-top: var(--s5);
  padding: var(--s4);
  border-radius: var(--radius);
  border-left: 4px solid var(--line);
  background: var(--card);
}
.feedback.ok { background: var(--olive-soft); border-left-color: var(--olive); }
.feedback.bad { background: var(--red-soft); border-left-color: var(--red); }
.feedback.neutral { background: var(--clay-soft); border-left-color: var(--clay); }
.feedback .btn { display: block; width: 100%; margin-top: var(--s3); }
.answer-key { margin-top: var(--s1); }

.transcript { min-height: 1.4em; margin: var(--s3) 0; color: var(--muted); }

.typing { display: flex; gap: var(--s2); margin-top: var(--s3); }
.typing input {
  flex: 1;
  min-height: 48px;
  font: inherit;
  padding: var(--s2) var(--s3);
  border: 1.5px solid var(--edge);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}

.result { text-align: center; padding-top: var(--s6); }
.result .xp { font-family: var(--serif); font-size: 2rem; color: var(--clay); font-weight: 600; }
.result .btn { margin-top: var(--s4); }

/* Conversa com avatar */
.conv { display: flex; flex-direction: column; gap: var(--s3); }
.conv-box { padding: var(--s4); border-radius: var(--radius-lg); background: var(--card); border: 1px solid var(--line); }
.avatar { text-align: center; }
.avatar-svg { width: 150px; height: 150px; }
.avatar-name { margin-top: var(--s1); font-weight: 600; }
.avatar.speaking .avatar-svg { animation: bob 0.5s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-3px); } }
.mouth.open { transform-origin: 100px 120px; }
.avatar.speaking .mouth.closed { display: none; }
.avatar:not(.speaking) .mouth.open { display: none; }
.avatar.speaking .mouth.open { animation: talk 0.25s ease-in-out infinite alternate; }
@keyframes talk { from { transform: scaleY(0.3); } to { transform: scaleY(1.4); } }

.chat { display: flex; flex-direction: column; gap: var(--s2); }
.bubble { max-width: 82%; padding: var(--s3) var(--s4); border-radius: 16px; }
.bubble.partner { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.bubble.me { align-self: flex-end; background: var(--ink); color: #fff; }

.hint { min-height: 1.2em; color: var(--muted); font-size: 0.95rem; }

/* Controlos de voz */
.controls { display: flex; gap: var(--s2); align-items: center; margin: var(--s2) 0 var(--s4); }
.controls .mic { flex: 1; }
.speed { font: inherit; min-height: 48px; padding: var(--s2); border: 1.5px solid var(--edge); border-radius: 10px; background: var(--card); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.muted { color: var(--muted); }
.small { font-size: 0.9rem; margin: var(--s1) 0; }
.level { font-family: var(--serif); font-size: 1.8rem; font-weight: 600; margin: var(--s1) 0; }

.notice {
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  background: var(--clay-soft);
  color: var(--ink);
  border-left: 4px solid var(--clay);
  margin: var(--s3) 0;
}

/* Cartões de estado (diagnóstico e percurso) */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s4);
  margin: var(--s3) 0;
}
.card .btn { display: block; width: 100%; margin-top: var(--s2); text-align: left; }

.comp-row {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}

.badge {
  display: inline-block;
  padding: 2px var(--s2);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--line);
  color: var(--ink);
}
.badge.ok { background: var(--olive-soft); color: var(--olive); }
.badge.warn { background: var(--clay-soft); color: var(--clay); }
.badge.neutral { background: var(--line); color: var(--muted); }

.check { display: flex; align-items: center; gap: var(--s2); min-height: 48px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

/* Idiomas: escolha em cartões compactos */
.lang-cards { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s2) 0 var(--s4); }
.lang-card {
  min-height: 48px;
  padding: var(--s2) var(--s4);
  font: inherit;
  text-align: left;
  border: 1.5px solid var(--edge);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
}
.lang-card.active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.lang-card:disabled { opacity: 0.6; cursor: default; }
.lang-card small { display: block; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.actions .btn { flex: 1; }
.diag-top { display: flex; align-items: center; gap: var(--s2); }
.diag-top .progress { flex: 1; }
.diag-label { color: var(--muted); font-size: 0.95rem; margin: 0 0 var(--s1); }

.controls { flex-wrap: wrap; }
.controls-label { flex-basis: 100%; }
.controls-label + .chips { flex-basis: 100%; }
.controls-label { font-size: 0.9rem; color: var(--muted); margin: var(--s3) 0 var(--s1); font-weight: 600; letter-spacing: 0.02em; }

/* Novo perfil e campos de escrita */
.new-profile { display: grid; gap: var(--s2); margin: var(--s3) 0; padding: var(--s3); border: 1px solid var(--line); border-radius: var(--radius); }
.new-profile input {
  min-height: 48px;
  font: inherit;
  font-size: 1rem;
  padding: var(--s2) var(--s3);
  border-radius: 10px;
  border: 1.5px solid var(--edge);
  background: var(--card);
}

.write-input {
  width: 100%;
  min-height: 96px;
  font: inherit;
  font-size: 1.1rem;
  padding: var(--s3);
  border-radius: 10px;
  border: 1.5px solid var(--edge);
  background: var(--card);
  color: var(--ink);
  box-sizing: border-box;
}
.write-input:disabled { background: var(--paper); }

.word-check { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--s3) 0; }
.word-check .chip { cursor: default; }
.compare { display: grid; gap: var(--s3); margin-top: var(--s3); }
.compare audio { width: 100%; }

.write-report {
  margin-top: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  display: grid;
  gap: 6px;
}
.write-report .btn { justify-self: start; }

/* Teste de nível rápido: página própria, logo após o nome */
.welcome h1, .quick-test h1 { font-size: 2.2rem; }
.quick-box { margin-top: var(--s4); }
.quick-box .btn.opt { font-size: 1.05rem; }

/* Estado de foco visível em todos os controlos (teclado e leitores de ecrã) */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
