/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-5);
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: var(--primary);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
}

.btn-block {
  width: 100%;
}

.btn-small {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: 0.9rem;
}

.btn-icon {
  width: var(--tap);
  padding: 0;
  font-size: 1.25rem;
}

/* ---------- Formulários ---------- */
.stack {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-1);
  font-weight: 600;
}

.field input,
.field select {
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 400;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  outline: none;
}

.checkbox {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  font-size: 0.95rem;
}

.checkbox input {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex: none;
  accent-color: var(--primary);
}

.form-error {
  margin: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 600;
}

/* ---------- Abas ---------- */
.tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-1);
  border-radius: 999px;
  background: var(--surface-2);
}

.tab {
  flex: 1;
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Barra de progresso ---------- */
progress-bar {
  display: block;
}

.progress-track {
  position: relative;
  display: block;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: var(--text);
  opacity: 0.45;
}

.progress-mark.reached {
  opacity: 0.9;
  background: var(--surface);
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.6s ease;
}

progress-bar[level="iniciante"] .progress-fill {
  background: var(--level-iniciante);
}

progress-bar[level="medio"] .progress-fill {
  background: var(--level-medio);
}

progress-bar[level="avancado"] .progress-fill {
  background: var(--level-avancado);
}

progress-bar[level="expert"] .progress-fill {
  background: var(--level-expert);
}

/* ---------- Estrelas ---------- */
star-rating {
  display: inline-flex;
  gap: 2px;
  font-size: 1.2rem;
  line-height: 1;
}

.star {
  color: var(--border);
}

.star.on {
  color: #f5b301;
}

star-rating.stars-big {
  font-size: 3rem;
  gap: var(--space-2);
}

star-rating.stars-big .star.on {
  animation: pop 0.4s ease both;
}

star-rating.stars-big .star:nth-child(2) {
  animation-delay: 0.15s;
}

star-rating.stars-big .star:nth-child(3) {
  animation-delay: 0.3s;
}

/* ---------- Selos e chips ---------- */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

.level-iniciante {
  background: var(--level-iniciante);
}

.level-medio {
  background: var(--level-medio);
}

.level-avancado {
  background: var(--level-avancado);
}

.level-expert {
  background: var(--level-expert);
}

.chip {
  display: inline-block;
  padding: 2px var(--space-3);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}

.status-practicing {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-mastered {
  background: var(--success-bg);
  color: var(--success);
}

.status-needsReview {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---------- Teclado numérico ---------- */
numeric-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  max-width: 320px;
  margin-inline: auto;
}

.key {
  min-height: 56px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
}

.key:active {
  transform: scale(0.95);
}

.key:disabled {
  opacity: 0.5;
  cursor: default;
}

.key-ok {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-size: 1.1rem;
}

.key-back {
  background: var(--surface-2);
}

/* ---------- Respostas ---------- */
.answer-display {
  display: block;
  min-width: 160px;
  max-width: 240px;
  margin: 0 auto var(--space-4);
  padding: var(--space-2) var(--space-4);
  border: 3px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 2.25rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.answer-display.empty {
  color: var(--text-muted);
  border-style: dashed;
}

.answer-display.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.answer-display.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
  animation: shake 0.35s ease;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
}

.choice {
  min-height: 64px;
  padding: var(--space-3);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.choice-big {
  font-size: 2rem;
}

.choice:hover:not(:disabled) {
  border-color: var(--primary);
}

.choice:active:not(:disabled) {
  transform: scale(0.97);
}

.choice:disabled {
  cursor: default;
}

.choice.selected {
  border-color: var(--primary);
}

.choice.correct {
  border-color: var(--success);
  background: var(--success-bg);
  animation: pop 0.3s ease;
}

.choice.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  animation: shake 0.35s ease;
}

/* Sequências */
.sequence {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.seq-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 52px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 1.5rem;
  font-weight: 700;
}

.seq-blank {
  border: 3px dashed var(--primary);
  background: transparent;
  color: var(--primary);
}

.seq-blank.correct {
  border-style: solid;
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.seq-blank.filled {
  border-style: solid;
  color: var(--text);
}

/* ---------- Animações ---------- */
@keyframes pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  70% {
    transform: scale(1.15);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

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

/* ---------- Teclado: teclas extras (−, vírgula) ---------- */
.key-minus,
.key-comma {
  background: var(--surface-2);
}

/* ---------- Verdadeiro/falso e opções longas ---------- */
.choices-two {
  grid-template-columns: repeat(2, 1fr);
}

.choice-long {
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
}

/* ---------- Ordenar ---------- */
.answer-order {
  display: grid;
  gap: var(--space-3);
}

.order-slots {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3);
  list-style: none;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 72px;
}

.order-slots.correct {
  border-color: var(--success);
  border-style: solid;
  background: var(--success-bg);
}

.order-slots.wrong {
  border-color: var(--danger);
  border-style: solid;
  background: var(--danger-bg);
}

.order-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 52px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.order-slot.filled {
  background: transparent;
}

.order-pool {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  min-height: 56px;
}

.chip-btn {
  min-width: 64px;
  min-height: 52px;
  padding: 0 var(--space-4);
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}

.chip-btn:hover:not(:disabled) {
  border-color: var(--primary);
}

.chip-btn.placed {
  border-color: var(--primary);
}

.order-solution {
  margin: 0;
  font-weight: 700;
  text-align: center;
}

/* ---------- Grade (Sudoku / quadrado mágico) ---------- */
.answer-grid {
  display: grid;
  gap: var(--space-4);
  justify-items: center;
}

.grid-board {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: min(100%, calc(var(--n) * 56px));
  border: 3px solid var(--text);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--text);
  gap: 1px;
}

.cell {
  aspect-ratio: 1;
  border: 0;
  background: var(--surface);
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
}

.cell.given {
  color: var(--text);
  background: var(--surface-2);
  cursor: default;
}

/* Linhas mais grossas entre os blocos: a célula encolhe e o fundo escuro aparece. */
.cell.box-right {
  margin-right: 3px;
}

.cell.box-bottom {
  margin-bottom: 3px;
}

.cell.selected {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}

.cell.fixed {
  color: var(--danger);
  text-decoration: underline;
}

.grid-board.correct {
  border-color: var(--success);
  background: var(--success);
}

.grid-board.wrong {
  border-color: var(--danger);
  background: var(--danger);
}

.grid-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  max-width: 420px;
}

.grid-palette .key {
  min-width: 52px;
}

.confirm-btn {
  max-width: 420px;
  justify-self: center;
}

/* ---------- Frações (figuras) ---------- */
.figure-wrap {
  display: flex;
  justify-content: center;
}

.fraction-figure {
  width: min(100%, 320px);
  height: auto;
  overflow: visible;
}

.fraction-figure.is-circle {
  width: min(70%, 220px);
}

.fraction-part {
  fill: var(--surface-2);
  stroke: var(--surface);
  stroke-width: 2;
  transition: fill 0.15s ease;
}

.fraction-figure.is-circle .fraction-part {
  stroke-width: 3;
}

.fraction-part.filled {
  fill: var(--chart-1);
}

.is-interactive .fraction-part {
  cursor: pointer;
}

.is-interactive .fraction-part:hover {
  fill: color-mix(in srgb, var(--chart-1) 35%, var(--surface-2));
}

.is-interactive .fraction-part.filled:hover {
  fill: var(--chart-1);
}

.is-interactive .fraction-part:focus-visible {
  outline: none;
  stroke: var(--text);
  stroke-width: 3;
}

.fraction-figure.correct .fraction-part.filled {
  fill: var(--success);
}

.fraction-figure.wrong .fraction-part.filled {
  fill: var(--danger);
}

.answer-paint {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
}

/* ---------- Gráfico de histórico ---------- */
.history {
  display: grid;
  gap: var(--space-3);
}

.chart-wrap {
  position: relative;
}

.history-chart {
  display: block;
  width: 100%;
  height: auto;
}

.history-chart .grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.history-chart .axis {
  stroke: var(--text-muted);
  stroke-width: 1;
}

.history-chart .tick {
  fill: var(--text-muted);
  font-size: 12px;
}

.history-chart .value {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.history-chart .bar {
  fill: var(--chart-1);
}

.history-chart .hit {
  fill: transparent;
  cursor: default;
  outline: none;
}

.history-chart .hit.active,
.history-chart .hit:focus-visible {
  fill: color-mix(in srgb, var(--text) 6%, transparent);
}

.chart-tooltip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  display: grid;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  white-space: nowrap;
  pointer-events: none;
}

.chart-tooltip.align-end {
  transform: translateX(-100%);
}

.chart-tooltip.align-start {
  transform: none;
}

.chart-table summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.chart-table table {
  width: 100%;
  margin-top: var(--space-2);
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.chart-table th,
.chart-table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.chart-table th[scope="row"],
.chart-table thead th:first-child {
  text-align: left;
}

/* ---------- Medalhas ---------- */
.medal-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3);
}

.medal {
  display: grid;
  justify-items: center;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  opacity: 0.55;
}

.medal.earned {
  opacity: 1;
  background: var(--surface-2);
}

.medal-icon {
  font-size: 2rem;
  line-height: 1.2;
}

.medal strong {
  font-size: 0.95rem;
}

/* ---------- Avatar ---------- */
.avatar-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  background: var(--avatar-padrao);
  line-height: 1;
}

.avatar-badge.size-sm {
  width: 30px;
  height: 30px;
  font-size: 1.1rem;
}

.avatar-badge.size-md {
  width: 44px;
  height: 44px;
  font-size: 1.6rem;
}

.avatar-badge.size-lg {
  width: 64px;
  height: 64px;
  font-size: 2.3rem;
}

.avatar-badge.size-xl {
  width: 128px;
  height: 128px;
  font-size: 4.5rem;
}

.avatar-accessory {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55em;
  line-height: 1;
}

.avatar-accessory.acc-cabeca {
  top: -18%;
}

.avatar-accessory.acc-rosto {
  top: 30%;
  font-size: 0.5em;
}

.avatar-accessory.acc-peito {
  top: auto;
  bottom: -10%;
  left: 78%;
}

.color-menta {
  background: var(--avatar-menta);
}

.color-lavanda {
  background: var(--avatar-lavanda);
}

.color-pessego {
  background: var(--avatar-pessego);
}

.color-ceu {
  background: var(--avatar-ceu);
}

.color-ouro {
  background: var(--avatar-ouro);
  box-shadow: 0 0 0 3px #e0b000;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: var(--space-2);
}

.item-btn {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 72px;
  padding: var(--space-2);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.item-btn.selected {
  border-color: var(--primary);
}

.item-btn.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.item-emoji {
  font-size: 1.8rem;
  line-height: 1.2;
}

.item-lock {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.color-swatch {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--avatar-padrao);
  border: 1px solid var(--border);
}

.avatar-preview {
  display: flex;
  justify-content: center;
  padding: var(--space-4) 0 var(--space-2);
}

/* ---------- Diversos ---------- */
.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.code-block {
  margin: 0;
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

.listen-btn {
  justify-self: start;
}

.option-group {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.option-group legend {
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  cursor: pointer;
}

.option input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.inline-form input {
  flex: 1;
  min-width: 160px;
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
