/* ==========================================================================
   Treinador de Escuta HSK — tema escuro/sóbrio (anexo §1)
   Fundo grafite (não preto puro), texto de alto contraste, hanzi generoso,
   uma cor de destaque dessaturada, erros em laranja suave. Minimalista.
   ========================================================================== */

:root {
  /* Fundos */
  --bg: #14161a;
  --bg-elev: #1b1e24;
  --bg-input: #21252c;
  --bg-input-focus: #262b33;
  --border: #2c313a;
  --border-strong: #3a4150;

  /* Texto */
  --text: #e7e9ee;
  --text-muted: #9aa3af;
  --text-dim: #6b7480;

  /* Destaque (verde-azulado dessaturado) */
  --accent: #5bb5a3;
  --accent-hover: #6cc6b3;
  --accent-ink: #0c1513;
  --accent-soft: rgba(91, 181, 163, 0.14);

  /* Estados */
  --ok: #6cc6a0;
  --ok-soft: rgba(108, 198, 160, 0.14);
  --err: #e08a6a;
  --err-soft: rgba(224, 138, 106, 0.14);
  --warn: #d6b15c;
  --warn-soft: rgba(214, 177, 92, 0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 640px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-hanzi: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei",
    "Hiragino Sans GB", "Heiti SC", var(--font);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  justify-content: center;
}
.brand {
  width: 100%;
  max-width: var(--maxw);
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  font-family: var(--font-hanzi);
  font-size: 1.5rem;
  color: var(--accent);
  background: var(--accent-soft);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}
.brand-name {
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand-tag {
  color: var(--accent);
}

/* ---------- Layout ---------- */
.stage {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 28px 20px 48px;
}
.screen {
  width: 100%;
  max-width: var(--maxw);
  display: none;
  animation: fade 0.18s ease;
}
.screen.is-active {
  display: block;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.screen-title {
  font-size: 1.5rem;
  font-weight: 650;
  margin: 0 0 6px;
}
.screen-title.sm {
  font-size: 1.2rem;
}
.screen-sub {
  color: var(--text-muted);
  margin: 0 0 24px;
}
.subhead {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 600;
  margin: 28px 0 12px;
}

.footnote {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 16px 20px 28px;
}

/* ---------- Campos ---------- */
.field {
  margin-bottom: 22px;
}
.field-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 9px;
}
.muted {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.85em;
}

.input,
.select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input-focus);
}
.input::placeholder {
  color: var(--text-dim);
}
.input-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.35rem;
  letter-spacing: 2px;
}
.inline {
  display: flex;
  gap: 10px;
}
.inline .input {
  flex: 1;
}

.range {
  width: 100%;
  accent-color: var(--accent);
}
.pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.8rem;
  margin-left: 6px;
  vertical-align: middle;
}

/* Segmented control */
.seg {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.seg button {
  flex: 1;
  min-width: 72px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 11px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.14s;
}
.seg button:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}
.seg button.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.seg button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Radios */
.radios {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.radio {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.14s;
}
.radio:hover {
  border-color: var(--border-strong);
}
.radio input {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
}
.radio:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Advanced (backend) */
.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  margin-bottom: 22px;
  background: var(--bg-elev);
}
.advanced summary {
  cursor: pointer;
  padding: 13px 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.advanced[open] summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.advanced .field {
  margin-bottom: 16px;
}

.hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 8px 0 0;
  min-height: 1em;
}
.hint-ok {
  color: var(--ok);
}
.hint-err {
  color: var(--err);
}

/* ---------- Botões ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--bg-input);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-lg {
  padding: 15px 22px;
  font-size: 1.05rem;
  width: 100%;
}
.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 28px;
}

.linklike {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px;
}
.linklike:hover {
  color: var(--err);
}

/* ---------- Alertas ---------- */
.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
  margin: 0 0 4px;
}
.alert-error {
  background: var(--err-soft);
  color: var(--err);
  border: 1px solid var(--err);
}
.alert-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn);
}

/* ========================================================================
   TELA 2 — Treino
   ======================================================================== */
.train-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 26px;
}
.progress-chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
}
.listen-area {
  text-align: center;
  margin: 18px 0 30px;
}
.btn-listen {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  font-size: 1.3rem;
  font-weight: 600;
  font-family: inherit;
  padding: 22px 46px;
  cursor: pointer;
  transition: all 0.14s;
}
.btn-listen:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-listen:active:not(:disabled) {
  transform: scale(0.98);
}
.btn-listen:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.play-icon {
  margin-right: 6px;
}
.reps {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 16px 0 0;
}

/* ========================================================================
   TELA 3 — Correção
   ======================================================================== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card-title {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.reveal {
  text-align: center;
  border-color: var(--border-strong);
}
.reveal-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.hanzi-big {
  font-family: var(--font-hanzi);
  font-size: 2.6rem;
  line-height: 1.25;
  letter-spacing: 3px;
}
.pinyin {
  color: var(--accent);
  font-size: 1.05rem;
  margin-top: 8px;
}
.ref-pt {
  color: var(--text);
  margin-top: 12px;
}
.ref-tag,
.lbl {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-right: 6px;
}

/* Status chips */
.status {
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 4px 12px;
}
.status-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.status-err {
  background: var(--err-soft);
  color: var(--err);
}
.status-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

/* Diff alinhado */
.diff {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: stretch;
  font-family: var(--font-hanzi);
}
.diff-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  margin-right: 6px;
  font-family: var(--font);
}
.diff-labels span {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  height: 1.9rem;
  display: flex;
  align-items: center;
}
.diff-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-radius: 6px;
  padding: 3px 2px;
  min-width: 1.9rem;
}
.diff-col .t,
.diff-col .u {
  font-size: 1.5rem;
  height: 1.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.diff-col .u {
  font-size: 1.15rem;
}
.diff-igual .t {
  color: var(--text);
}
.diff-igual .u {
  color: var(--text-dim);
}
.diff-sub {
  background: var(--err-soft);
}
.diff-sub .t {
  color: var(--text-muted);
  text-decoration: line-through;
}
.diff-sub .u {
  color: var(--err);
  font-weight: 600;
}
.diff-del {
  background: var(--err-soft);
}
.diff-del .t {
  color: var(--err);
  font-weight: 600;
}
.diff-del .u {
  color: var(--text-dim);
}
.diff-ins {
  background: var(--warn-soft);
}
.diff-ins .t {
  color: var(--text-dim);
}
.diff-ins .u {
  color: var(--warn);
  font-weight: 600;
}

.errlist {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.errlist li {
  font-size: 0.9rem;
  color: var(--text);
  padding-left: 16px;
  position: relative;
}
.errlist li::before {
  content: "›";
  position: absolute;
  left: 0;
  color: var(--err);
}

.trad-detail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}
.dim {
  color: var(--text-dim);
}

/* IA */
.card-ai {
  border-color: var(--border-strong);
}
.ai-state {
  margin: 14px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.ai-state-err {
  color: var(--err);
}
.ai-result {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.ai-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.ai-block p {
  margin: 8px 0 0;
  font-size: 0.92rem;
  color: var(--text);
}
.tag {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.78rem;
}
.tag-err {
  border-color: var(--err);
  color: var(--err);
}

/* ========================================================================
   TELA 4 — Resumo
   ======================================================================== */
.score-row {
  display: flex;
  gap: 14px;
}
.score-card {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.score-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.score-num {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.bar {
  background: var(--bg-input);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.bar-thin {
  height: 6px;
  display: inline-block;
  vertical-align: middle;
}
.bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}
.bar-fill-warn {
  background: var(--warn);
}

.wrong-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.wrong-list li {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.wrong-list .empty {
  text-align: center;
  color: var(--text-muted);
}
.wrong-hanzi {
  font-family: var(--font-hanzi);
  font-size: 1.5rem;
  letter-spacing: 2px;
}
.wrong-pt {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 4px 0 10px;
}
.wrong-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ========================================================================
   TELA 5 — Estatísticas
   ======================================================================== */
.stat-big {
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.stat-big-num {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--accent);
}
.stat-big-lbl {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.stat-block {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  margin: 14px 0 8px;
}
.stat-row:first-child {
  margin-top: 0;
}
.stat-lbl {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.stat-val {
  font-weight: 600;
}
.stat-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.stat-line:last-child {
  margin-bottom: 0;
}
.stat-line-lbl {
  width: 38%;
  font-size: 0.88rem;
  color: var(--text);
}
.stat-line .bar {
  flex: 1;
}
.stat-line-val {
  width: 32px;
  text-align: right;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.stat-duo {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
}
.duo-card {
  flex: 1;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.duo-num {
  font-size: 1.8rem;
  font-weight: 700;
}
.duo-lbl {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ========================================================================
   Responsivo
   ======================================================================== */
@media (max-width: 520px) {
  .stage {
    padding: 20px 16px 40px;
  }
  .hanzi-big {
    font-size: 2.1rem;
  }
  .score-row,
  .stat-duo {
    flex-direction: column;
  }
  .btn-listen {
    width: 100%;
    border-radius: var(--radius);
  }
}
