:root {
  --tinta: #17323c;
  --tinta-suave: #4d6a73;
  --papel: #f6efe1;
  --tarjeta: #fffdf8;
  --borde: #e2d6bd;
  --primario: #1f4e5f;
  --acento: #e2703a;
  --acento-sombra: #b4501f;
  --acierto: #3f9d5a;
  --acierto-suave: #e3f3e6;
  --error: #d64545;
  --error-suave: #fbe6e6;
  --resaltado: #ffe08a;
  --nota: #fff6dd;
  --fuente-titulos: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --fuente: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radio: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--papel);
  color: var(--tinta);
  font-family: var(--fuente);
  -webkit-tap-highlight-color: transparent;
}

button,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.pantalla {
  display: none;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.pantalla.activa {
  display: flex;
  flex-direction: column;
}

#inicio,
#resultado {
  background:
    radial-gradient(circle at 85% 10%, rgb(226 112 58 / 0.14), transparent 40%),
    radial-gradient(circle at 10% 90%, rgb(31 78 95 / 0.12), transparent 45%),
    var(--papel);
}

.contenido {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.antetitulo {
  margin: 0;
  font-family: var(--fuente-titulos);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--acento);
}

h1 {
  margin: -12px 0 0;
  font-family: var(--fuente-titulos);
  font-size: clamp(2.2rem, 9vw, 3.2rem);
  line-height: 1.05;
  color: var(--primario);
}

h1 span {
  color: var(--acento);
}

h2 {
  margin: 0 0 10px;
  font-family: var(--fuente-titulos);
  color: var(--primario);
}

.campo {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.campo > span {
  font-weight: 800;
  color: var(--tinta-suave);
}

/* ---------- Botones ---------- */

.boton {
  border: 0;
  border-radius: 999px;
  padding: 16px 24px;
  font-family: var(--fuente-titulos);
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.boton:active {
  transform: translateY(2px);
}

.boton:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.boton-principal {
  background: var(--acento);
  color: #fff;
  box-shadow: 0 4px 0 var(--acento-sombra);
}

.boton-secundario {
  background: #fff;
  color: var(--primario);
  box-shadow: inset 0 0 0 2px var(--primario), 0 4px 0 var(--primario);
}

.boton-pequeno {
  padding: 10px 18px;
  font-size: 1rem;
}

.boton-icono {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--primario);
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgb(23 50 60 / 0.18);
}

.botones {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.enlaces {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
}

.enlace {
  border: 0;
  background: none;
  padding: 10px 12px;
  color: var(--primario);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--acento);
  outline-offset: 2px;
}

/* ---------- Control segmentado (niveles y tipo de sugerencia) ---------- */

.segmentado {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  border-radius: 999px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--borde);
}

.segmentado-dos {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmentado label {
  position: relative;
}

.segmentado input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmentado span {
  display: block;
  padding: 10px 4px;
  border-radius: 999px;
  text-align: center;
  font-weight: 800;
  color: var(--tinta-suave);
}

.segmentado input:checked + span {
  background: var(--primario);
  color: #fff;
}

.segmentado input:focus-visible + span {
  outline: 3px solid var(--acento);
  outline-offset: 2px;
}

/* ---------- Temas ---------- */

.rejilla-temas {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 560px) {
  .rejilla-temas {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tarjeta-tema {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border-radius: var(--radio);
  background: var(--tarjeta);
  box-shadow: 0 0 0 2px var(--borde);
  cursor: pointer;
}

.tarjeta-tema input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tarjeta-tema:has(input:checked) {
  background: #fff;
  box-shadow: 0 0 0 3px var(--acento);
}

.tarjeta-tema:has(input:focus-visible) {
  outline: 3px solid var(--primario);
  outline-offset: 2px;
}

.tema-icono {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 46px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--primario);
  color: #fff;
  font-family: var(--fuente-titulos);
  font-weight: 600;
  white-space: nowrap;
}

.tarjeta-repaso .tema-icono {
  background: var(--acento);
}

.tema-nombre {
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.15;
}

.tema-nota {
  min-height: 1em;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--acento-sombra);
}

/* ---------- Ejercicio ---------- */

#ejercicio.activa {
  height: 100dvh;
}

.cabecera {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.cabecera-titulo {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.cabecera-titulo strong {
  overflow: hidden;
  font-family: var(--fuente-titulos);
  font-size: 1.05rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cabecera-titulo span {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--tinta-suave);
}

.marcador {
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  font-family: var(--fuente-titulos);
  font-weight: 600;
  box-shadow: 0 2px 6px rgb(23 50 60 / 0.12);
}

.barra-progreso {
  height: 6px;
  margin: 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--borde);
}

#progreso {
  width: 0;
  height: 100%;
  background: var(--acento);
  transition: width 0.3s ease;
}

.zona-ejercicio {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.enunciado {
  margin: auto 0 0;
  max-width: 100%;
  text-align: center;
  font-size: clamp(1.15rem, 4.8vw, 1.5rem);
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.enunciado em {
  font-style: normal;
  font-weight: 600;
  color: var(--primario);
}

.expresion {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--fuente-titulos);
  font-size: 1.15em;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

mark {
  padding: 0 2px;
  border-radius: 4px;
  background: var(--resaltado);
  color: inherit;
}

.hueco {
  display: inline-block;
  min-width: 1.2em;
  padding: 0 3px;
  border-bottom: 3px dashed var(--acento);
  color: var(--acento);
  text-align: center;
}

sup.hueco {
  min-width: 0.9em;
  border-bottom-width: 2px;
}

.hueco.lleno {
  border-bottom-style: solid;
}

.entrada {
  min-width: min(280px, 100%);
  max-width: 100%;
  min-height: 56px;
  padding: 10px 18px;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--borde);
  font-family: var(--fuente-titulos);
  font-size: 1.6rem;
  text-align: center;
  overflow-wrap: anywhere;
}

.entrada.mal {
  color: var(--error);
  box-shadow: inset 0 0 0 3px var(--error);
}

.entrada-vacia {
  font-family: var(--fuente);
  font-size: 1rem;
  color: #b5a98f;
}

.aviso {
  margin: 0 0 auto;
  min-height: 1.4em;
  text-align: center;
  font-weight: 700;
}

.aviso.bien {
  font-size: 1.2rem;
  color: var(--acierto);
}

.aviso.mal {
  color: var(--error);
}

.pista {
  display: block;
  margin-top: 6px;
  font-weight: 600;
  color: var(--tinta-suave);
}

.tarjeta {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radio);
  background: #fff;
  box-shadow: 0 2px 8px rgb(23 50 60 / 0.1);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.tarjeta p {
  margin: 0;
}

.sabias {
  background: var(--nota);
}

.explicacion .enlace {
  padding: 8px 0 0;
}

.panel-respuesta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--tarjeta);
  box-shadow: 0 -2px 10px rgb(23 50 60 / 0.08);
}

.teclado {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.tecla {
  height: 54px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 3px 0 var(--borde), inset 0 0 0 2px var(--borde);
  font-family: var(--fuente-titulos);
  font-size: 1.5rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.tecla:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--borde), inset 0 0 0 2px var(--borde);
}

.tecla[data-tecla='0'],
.tecla-aceptar {
  grid-column: span 2;
}

.tecla-aceptar {
  background: var(--acento);
  color: #fff;
  font-size: 1.2rem;
  box-shadow: 0 3px 0 var(--acento-sombra);
}

.tecla-borrar,
.tecla-extra {
  background: #eef3f4;
  color: var(--primario);
}

.opciones-respuesta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.boton-opcion {
  min-height: 56px;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 var(--borde), inset 0 0 0 2px var(--borde);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}

.boton-opcion:disabled {
  cursor: default;
}

.boton-opcion.fallo {
  background: var(--error-suave);
  color: var(--error);
  box-shadow: inset 0 0 0 3px var(--error);
}

.boton-opcion.acierto,
.boton-opcion.correcta {
  background: var(--acierto-suave);
  color: var(--acierto);
  box-shadow: inset 0 0 0 3px var(--acierto);
}

#boton-siguiente {
  width: 100%;
  max-width: 420px;
}

/* ---------- Resultado ---------- */

.nota {
  text-align: center;
  font-family: var(--fuente-titulos);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primario);
}

.nota small {
  font-size: 1.8rem;
  color: var(--tinta-suave);
}

.resumen,
.nuevo-record {
  margin: 0;
  text-align: center;
  font-weight: 800;
}

.nuevo-record {
  color: var(--acento);
}

.lista-repasar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lista-repasar li {
  padding: 12px 14px;
  border-radius: var(--radio);
  background: #fff;
  box-shadow: 0 1px 4px rgb(23 50 60 / 0.1);
  overflow-wrap: anywhere;
}

.repaso-enunciado {
  font-weight: 700;
}

.repaso-respuesta {
  margin-top: 4px;
  font-weight: 700;
  color: var(--acierto);
}

.repaso-explicacion {
  margin-top: 4px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--tinta-suave);
}

/* ---------- Diálogos ---------- */

.dialogo {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--papel);
  color: var(--tinta);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}

.dialogo::backdrop {
  background: rgb(23 50 60 / 0.45);
}

.dialogo-contenido {
  max-height: calc(100dvh - 120px);
  padding: 20px 20px 8px;
  overflow-y: auto;
  line-height: 1.55;
}

.dialogo-contenido h3 {
  margin: 18px 0 6px;
  font-family: var(--fuente-titulos);
}

.dialogo-pie {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px 18px;
}

.teoria table {
  margin: 8px 0;
  border-collapse: collapse;
}

.teoria th,
.teoria td {
  padding: 4px 10px;
  border: 1px solid var(--borde);
  text-align: left;
}

.teoria .ejemplo {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff;
  overflow-wrap: anywhere;
}

.formulario-sugerencia {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

.formulario-sugerencia textarea {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px var(--borde);
  resize: vertical;
}

.sugerencia-pie {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: -6px 0 0;
  font-size: 0.85rem;
  color: var(--tinta-suave);
}

.trampa {
  position: absolute;
  left: -9999px;
}

.sugerencia-estado {
  min-height: 1.2em;
  margin: 0;
  font-weight: 700;
}

.sugerencia-estado.bien {
  color: var(--acierto);
}

.sugerencia-estado.mal {
  color: var(--error);
}

.sugerencia-botones {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Actividades (fases 2-4) ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.chip span {
  display: block;
  padding: 9px 14px;
  border-radius: 999px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--borde);
  font-weight: 800;
  font-size: 0.95rem;
}

.chip input:checked + span {
  background: var(--primario);
  color: #fff;
  box-shadow: none;
}

.chip input:focus-visible + span {
  outline: 3px solid var(--acento);
  outline-offset: 2px;
}

.record {
  min-height: 1.2em;
  margin: 0;
  font-weight: 800;
  color: var(--acento-sombra);
}

#aviso-inicio:empty {
  display: none;
}

.marcador.poco-tiempo {
  background: var(--error);
  color: #fff;
}

/* Paso a paso */

.contexto {
  max-width: 100%;
  margin-top: auto;
  padding: 12px 14px;
  border-radius: var(--radio);
  background: #fff;
  box-shadow: 0 2px 8px rgb(23 50 60 / 0.1);
  font-family: var(--fuente-titulos);
  font-size: clamp(1.15rem, 5vw, 1.45rem);
  line-height: 1.8;
  text-align: center;
  overflow-wrap: anywhere;
}

.contexto + .enunciado {
  margin-top: 0;
}

.operacion {
  min-width: 30px;
  min-height: 34px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: #eef3f4;
  box-shadow: inset 0 0 0 2px var(--primario);
  color: var(--primario);
  font: inherit;
  cursor: pointer;
}

.operacion.mal {
  background: var(--error-suave);
  box-shadow: inset 0 0 0 2px var(--error);
  color: var(--error);
}

.escalera {
  margin: 0 auto;
  border-collapse: collapse;
}

.escalera td {
  min-width: 3.2em;
  padding: 2px 12px;
  text-align: right;
}

.escalera td:first-child {
  border-right: 3px solid var(--primario);
}

/* Juegos */

#juego.activa {
  height: 100dvh;
}

.zona-juego {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.instruccion {
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.45;
}

.numero-grande {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--fuente-titulos);
  font-size: clamp(1.6rem, 8vw, 2.2rem);
}

.tablero {
  width: 100%;
}

.tabla-valores {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.tabla-valores th {
  padding: 3px 0;
  font-size: 0.7rem;
  line-height: 1.1;
  color: #fff;
  background: var(--primario);
  border: 1px solid var(--papel);
  overflow-wrap: anywhere;
}

.tabla-valores th.grupo-1 {
  background: var(--acento);
}

.tabla-valores td {
  padding: 2px;
}

.celda {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--borde);
  font-family: var(--fuente-titulos);
  font-size: 1.4rem;
  cursor: pointer;
}

.celda.puesta {
  background: var(--acierto-suave);
  color: var(--acierto);
  box-shadow: inset 0 0 0 2px var(--acierto);
}

.celda.mal,
.casilla.mal {
  background: var(--error-suave);
  box-shadow: inset 0 0 0 2px var(--error);
}

.rejilla-numeros {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
}

.casilla {
  aspect-ratio: 1;
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--borde);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.casilla.encontrada,
.casilla.primo {
  background: var(--acierto-suave);
  color: var(--acierto);
  box-shadow: inset 0 0 0 2px var(--acierto);
}

.casilla.primo-actual {
  background: var(--primario);
  color: #fff;
}

.casilla.tachada {
  color: #b5a98f;
  text-decoration: line-through 2px var(--error);
  background: var(--inactiva, #efe8da);
}

.casilla.faltaba {
  background: #ffe7c7;
  color: var(--acento-sombra);
  box-shadow: inset 0 0 0 2px var(--acento);
}

.arbol {
  display: flex;
  justify-content: safe center;
  overflow-x: auto;
  padding-bottom: 6px;
}

.nodo {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hijos {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  padding-top: 8px;
  border-top: 2px solid var(--borde);
}

.nodo-valor {
  min-width: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--borde);
  font-family: var(--fuente-titulos);
  font-size: 1.05rem;
  text-align: center;
}

.nodo-valor.compuesta {
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--primario);
}

.nodo-valor.elegida {
  background: var(--primario);
  color: #fff;
}

.nodo-valor.prima {
  background: var(--acierto-suave);
  color: var(--acierto);
  box-shadow: inset 0 0 0 2px var(--acierto);
}

#juego-siguiente {
  width: 100%;
  max-width: 420px;
}

/* En tableros largos (criba de 200) el aviso queda pegado abajo para que se lea sin desplazar. */
#juego-aviso:not(:empty) {
  position: sticky;
  bottom: -14px;
  z-index: 2;
  align-self: stretch;
  margin: 8px -12px -14px;
  padding: 8px 12px;
  background: var(--papel);
}

/* ---------- Curso y nivel (como en GeoFácil) ---------- */

.linea-nivel {
  margin: 2px 0 0;
  font-weight: 700;
  color: var(--tinta-suave);
}

.linea-nivel strong {
  color: var(--primario);
}

/* «Cambiar», junto a la línea del nivel en el inicio. */
.enlace-nivel {
  border: 0;
  background: none;
  padding: 0 2px;
  color: var(--primario);
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.curso-explicacion {
  margin: 0 0 14px;
  color: var(--tinta-suave);
  line-height: 1.4;
}

.dialogo-curso h2:focus {
  outline: none;
}

.opciones-curso {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* «Bachillerato o adulto» ocupa toda la fila. */
.opciones-curso .opcion:last-child {
  grid-column: 1 / -1;
}

.opciones-nivel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.opcion {
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 var(--borde), inset 0 0 0 2px var(--borde);
  font-weight: 800;
  cursor: pointer;
}

.opcion.elegida {
  background: var(--primario);
  color: #fff;
  box-shadow: none;
}

.cambio-nivel {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radio);
  background: #fff;
  box-shadow: 0 0 0 3px var(--borde);
  text-align: center;
  font-weight: 800;
}

.cambio-nivel.sube {
  box-shadow: 0 0 0 3px var(--acierto);
}
