/* Percepção Musical — folha de estilo única, mobile-first. */

:root {
  --fundo: #0f111a;
  --fundo-2: #171a27;
  --fundo-3: #1f2333;
  --borda: #2a2f42;
  --texto: #e8eaf2;
  --texto-2: #98a0b8;
  --acento: #6c8cff;
  --acento-2: #8f6cff;
  --certo: #34d399;
  --certo-fundo: #10281f;
  --errado: #fb7185;
  --errado-fundo: #2d1520;
  --aviso: #fbbf24;
  --raio: 14px;
  --sombra: 0 6px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

:root[data-tema="claro"] {
  --fundo: #f5f6fa;
  --fundo-2: #ffffff;
  --fundo-3: #eceef5;
  --borda: #d9dde8;
  --texto: #1b1e2b;
  --texto-2: #626a82;
  --acento: #3f5fe0;
  --acento-2: #7b45d6;
  --certo: #12855e;
  --certo-fundo: #dff5ec;
  --errado: #cf3050;
  --errado-fundo: #fde5ea;
  --sombra: 0 4px 18px rgba(20, 25, 45, .1);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-tema="escuro"]) {
    --fundo: #f5f6fa;
    --fundo-2: #ffffff;
    --fundo-3: #eceef5;
    --borda: #d9dde8;
    --texto: #1b1e2b;
    --texto-2: #626a82;
    --acento: #3f5fe0;
    --acento-2: #7b45d6;
    --certo: #12855e;
    --certo-fundo: #dff5ec;
    --errado: #cf3050;
    --errado-fundo: #fde5ea;
    --sombra: 0 4px 18px rgba(20, 25, 45, .1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 0 max(16px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  touch-action: manipulation;
}

h2 { font-size: 1.25rem; margin: 0; }
h3 { font-size: 1.02rem; margin: 0 0 4px; }
p { margin: 0 0 6px; }

/* --------------------------------------------------------------- cabeçalho */

#cabecalho {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--fundo) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borda);
}

.marca {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--texto);
  text-decoration: none;
  white-space: nowrap;
}
.marca-icone { font-size: 1.4rem; color: var(--acento); }

.cabecalho-metricas { display: flex; align-items: center; gap: 12px; }
.metrica { display: flex; flex-direction: column; gap: 3px; min-width: 42px; }
.metrica-valor { font-size: .82rem; font-weight: 600; color: var(--texto-2); white-space: nowrap; }

/* ------------------------------------------------------------------- telas */

main { max-width: 720px; margin: 0 auto; }
.tela { display: flex; flex-direction: column; gap: 14px; }

.cabecalho-tela,
.cabecalho-exercicio {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cabecalho-exercicio h2 { flex: 1; display: flex; align-items: center; gap: 8px; }

.etiqueta {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--acento);
  color: #fff;
}

.titulo-secao {
  margin: 14px 0 0;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--texto-2);
}

/* ------------------------------------------------------------------ botões */

.botao {
  appearance: none;
  border: 1px solid var(--borda);
  background: var(--fundo-2);
  color: var(--texto);
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  min-height: 48px;
  border-radius: var(--raio);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform .06s, background .15s, border-color .15s;
}
.botao:active { transform: scale(.97); }
.botao.principal { background: var(--acento); border-color: transparent; color: #fff; }
.botao.secundario { background: var(--fundo-2); }
.botao.secundario.ativo { border-color: var(--acento); color: var(--acento); }
.botao.perigo { border-color: var(--errado); color: var(--errado); background: transparent; }
.botao.voltar { min-height: 42px; width: 42px; padding: 0; font-size: 1.2rem; flex: none; }
.botao.icone { min-height: 38px; width: 38px; padding: 0; font-size: 1.1rem; flex: none; }

.atalhos { display: flex; flex-wrap: wrap; gap: 10px; }
.atalhos .botao { flex: 1 1 160px; }

/* ------------------------------------------------------------------ cartões */

.grade-cartoes { display: grid; gap: 10px; }

.cartao {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  color: var(--texto);
  text-decoration: none;
  box-shadow: var(--sombra);
  transition: transform .06s, border-color .15s;
}
.cartao:active { transform: scale(.99); }
.cartao-icone {
  font-size: 1.6rem;
  line-height: 1;
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--acento), var(--acento-2));
  color: #fff;
}
.cartao-texto h3 { display: flex; align-items: center; gap: 8px; }
.cartao-texto p { color: var(--texto-2); font-size: .9rem; }
.cartao-texto .barra { margin: 7px 0 5px; }
.cartao-nivel {
  flex: none;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 99px;
  color: var(--acento);
  background: color-mix(in srgb, var(--acento) 14%, transparent);
}
.cartao-nota { font-size: .8rem !important; color: var(--texto-2); opacity: .85; }
.cartao-nota.bloqueado { color: var(--aviso); opacity: .9; }

.rodape { color: var(--texto-2); font-size: .82rem; text-align: center; margin-top: 8px; }

/* --------------------------------------------------------------- exercício */

.placar {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: .85rem;
  color: var(--texto-2);
  white-space: nowrap;
}
.placar-item b { color: var(--texto); font-size: 1rem; }
.placar-item.sequencia { min-width: 42px; text-align: right; }

.painel-questao {
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 16px;
  box-shadow: var(--sombra);
}
.enunciado { font-size: 1.02rem; margin-bottom: 12px; }
.controles { display: flex; flex-wrap: wrap; gap: 8px; }
.controles .botao { flex: 1 1 auto; }
.controles .botao.principal { flex: 2 1 160px; }

.grade-respostas {
  display: grid;
  /* minmax(0, 1fr): sem isso, uma palavra longa alarga a coluna e estoura a tela. */
  grid-template-columns: repeat(var(--colunas, 3), minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 520px) {
  .grade-respostas.largo { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.resposta {
  position: relative;
  appearance: none;
  border: 1px solid var(--borda);
  background: var(--fundo-2);
  color: var(--texto);
  font: inherit;
  min-height: 62px;
  padding: 10px 6px;
  border-radius: var(--raio);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .06s, background .12s, border-color .12s, opacity .2s;
}
.resposta:active { transform: scale(.96); }
.resposta-rotulo { font-size: 1.12rem; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.grade-respostas.largo .resposta-rotulo { font-size: .95rem; }
.resposta-sub { font-size: .7rem; color: var(--texto-2); line-height: 1.1; }
.resposta-tecla {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: .62rem;
  color: var(--texto-2);
  opacity: .45;
}
.resposta[disabled] { cursor: default; }
/* Ainda não liberado: continua no lugar, só que apagado e inerte. */
.resposta.bloqueada {
  background: transparent;
  border-style: dashed;
  color: var(--texto-2);
  opacity: .45;
  box-shadow: none;
}
.resposta.bloqueada .resposta-rotulo { font-weight: 600; }
.resposta.bloqueada .resposta-tecla { color: var(--aviso); opacity: .95; }
.resposta.certa { background: var(--certo-fundo); border-color: var(--certo); color: var(--certo); }
.resposta.errada { background: var(--errado-fundo); border-color: var(--errado); color: var(--errado); }
.resposta.apagada { opacity: .35; }

/* Em telas estreitas o toque não pode ficar apertado. */
@media (max-width: 380px) {
  .grade-respostas { grid-template-columns: repeat(min(var(--colunas, 3), 3), minmax(0, 1fr)); }
  .resposta-tecla { display: none; }
}

.feedback { border-radius: var(--raio); padding: 0; }
.feedback:not(:empty) { padding: 14px 16px; border: 1px solid var(--borda); background: var(--fundo-2); }
.feedback.certo:not(:empty) { background: var(--certo-fundo); border-color: var(--certo); }
.feedback.errado:not(:empty) { background: var(--errado-fundo); border-color: var(--errado); }
.feedback.pulada:not(:empty) { background: var(--fundo-3); }
.feedback-titulo { font-weight: 700; }
.feedback-detalhe { color: var(--texto-2); font-size: .9rem; }
.feedback .xp { color: var(--acento); font-weight: 700; }
.feedback .controles { margin-top: 10px; }

/* ---------------------------------------------------------------- progresso */

.painel-resumo {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 560px) { .painel-resumo { grid-template-columns: repeat(4, 1fr); } }

.resumo-bloco {
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.resumo-numero { font-size: 1.7rem; font-weight: 700; line-height: 1.6; }
.resumo-rotulo { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--texto-2); }
.resumo-sub { font-size: .78rem; color: var(--texto-2); opacity: .8; }

.anel .trilha { stroke: var(--fundo-3); }
.anel .valor { stroke: var(--acento); }
.anel-rotulo { fill: var(--texto); font-size: 15px; font-weight: 700; }

.barra { height: 8px; border-radius: 99px; background: var(--fundo-3); overflow: hidden; }
.barra.fina { height: 5px; }
.barra i { display: block; height: 100%; background: linear-gradient(90deg, var(--acento), var(--acento-2)); }

.grafico {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 110px;
  padding: 8px;
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
}
.grafico-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 4px; }
.grafico-col i { display: block; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--acento); }
.grafico-col span { font-size: .6rem; color: var(--texto-2); text-align: center; }

.lista-exercicios { display: flex; flex-direction: column; gap: 8px; }
.linha-exercicio { display: grid; grid-template-columns: 1fr auto 90px auto; align-items: center; gap: 10px; font-size: .9rem; }
.linha-nivel { font-size: .72rem; font-weight: 700; color: var(--acento); white-space: nowrap; }
.linha-valor { color: var(--texto-2); font-size: .8rem; white-space: nowrap; }

.lista-fracos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item-fraco {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 10px 12px;
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: 10px;
  font-size: .9rem;
}
.item-nome { font-weight: 600; }
.item-precisao { color: var(--errado); font-size: .82rem; text-align: right; }
.item-ex, .item-confusao { font-size: .76rem; color: var(--texto-2); }
.item-confusao { text-align: right; }

.dica { font-size: .84rem; color: var(--texto-2); }
.zona-perigo { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }

/* ------------------------------------------------------------------ ajustes */

.campo { display: flex; flex-direction: column; gap: 6px; }
.campo-rotulo { font-weight: 600; font-size: .92rem; }
.campo-dica { font-size: .8rem; color: var(--texto-2); }

.controle {
  appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  color: var(--texto);
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: 10px;
}
select.controle {
  background-image: linear-gradient(45deg, transparent 50%, var(--texto-2) 50%),
                    linear-gradient(135deg, var(--texto-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
input[type="range"].controle {
  min-height: 38px;
  padding: 0;
  background: transparent;
  border: none;
}
input[type="range"].controle::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: var(--fundo-3);
  border: 1px solid var(--borda);
}
input[type="range"].controle::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--acento);
  border: 2px solid var(--fundo-2);
  box-shadow: var(--sombra);
}
input[type="range"].controle::-moz-range-track {
  height: 6px;
  border-radius: 99px;
  background: var(--fundo-3);
  border: 1px solid var(--borda);
}
input[type="range"].controle::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid var(--fundo-2);
  border-radius: 50%;
  background: var(--acento);
}

.alternador { display: flex; flex-wrap: wrap; gap: 6px; }
.alternador-opcao {
  flex: 1 1 auto;
  appearance: none;
  min-height: 46px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  font-size: .88rem;
  color: var(--texto-2);
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: 10px;
  cursor: pointer;
}
.alternador-opcao.ativo { color: #fff; background: var(--acento); border-color: transparent; }

.bloco-desvios { display: flex; flex-direction: column; gap: 6px; }
.desvios { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.desvio {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 2px;
  background: var(--fundo-2);
  border: 1px solid var(--borda);
  border-radius: 8px;
}
.desvio-nota { font-size: .72rem; color: var(--texto-2); }
.desvio-valor { font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.desvio-valor.neutro { color: var(--texto-2); font-weight: 500; }

/* -------------------------------------------------------------------- avisos */

#aviso-audio {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 99px;
  background: var(--aviso);
  color: #241a00;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: var(--sombra);
  z-index: 40;
  display: none;
}
body.sem-audio #aviso-audio { display: block; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--fundo-3);
  border: 1px solid var(--borda);
  color: var(--texto);
  font-weight: 600;
  box-shadow: var(--sombra);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
#toast.visivel { opacity: 1; transform: translate(-50%, 0); }
#toast.sucesso { border-color: var(--certo); color: var(--certo); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
