:root {
  --fondo: #f6ecc6;
  --panel: #fffdf4;
  --tarjeta: #ffffff;
  --texto: #2f2c3a;
  --texto-suave: #55525f;
  --primario: #5a5a8c;
  --primario-texto: #ffffff;
  --dorado: #f2c14e;
  --acento: #b4472a;
  --bien: #bfe8c8;
  --bien-borde: #1c6b38;
  --mal: #f8cfc6;
  --mal-borde: #a93420;
  --borde: #2f2c3a;
  --radio: 14px;
  --grosor: 3px;
  --sombra: 4px 4px 0 var(--borde);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--fondo);
  color: var(--texto);
  font-family: -apple-system, "Helvetica Neue", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
  background: var(--panel);
  border: var(--grosor) solid var(--borde);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--borde);
}

h1 { font-size: 2.4rem; font-weight: 900; letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 16px; }
h2 { font-size: 1.4rem; font-weight: 800; line-height: 1.2; margin: 0 0 12px; }
p { margin: 0 0 12px; }

a { color: inherit; }

.tarjeta {
  background: var(--tarjeta);
  border: var(--grosor) solid var(--borde);
  border-radius: var(--radio);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--sombra);
}

.centrado { text-align: center; }

.solo-lector {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

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

.boton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 10px 20px;
  border: var(--grosor) solid var(--borde);
  border-radius: 14px;
  background: var(--tarjeta);
  color: var(--texto);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--borde);
}

.boton:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--borde); }
.boton:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }

.boton-principal {
  background: var(--primario);
  color: var(--primario-texto);
}

.fila-botones {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.boton-sonido { margin-top: 12px; font-size: 1rem; }

/* ---------- Portada ---------- */

.cabecera {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.cabecera h1 { margin: 0; }

.total-estrellas {
  background: var(--dorado);
  color: var(--texto);
  border: var(--grosor) solid var(--borde);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--borde);
  margin: 0;
  padding: 6px 16px;
  font-size: 1.4rem;
  font-weight: 800;
}

.lista-actividades {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.lista-actividades li { padding-top: 16px; }

.actividad {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 170px;
  padding: 14px;
  background: var(--tarjeta);
  border: var(--grosor) solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  color: var(--texto);
  text-decoration: none;
}

/* Pestaña de carpeta */
.actividad::before {
  content: "";
  position: absolute;
  top: -19px;
  left: 10px;
  width: 44%;
  height: 16px;
  background: var(--color, var(--dorado));
  border: var(--grosor) solid var(--borde);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.actividad:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--borde); }

.actividad-icono {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  background: var(--color, var(--dorado));
  border: var(--grosor) solid var(--borde);
  border-radius: 10px;
  font-size: 1.9rem;
  line-height: 1;
}

.actividad-titulo { font-size: 1.25rem; font-weight: 800; }
.actividad .estrellas { margin-top: auto; }

.estrellas { display: inline-flex; gap: 2px; font-size: 1.8rem; line-height: 1; }
.estrella { color: transparent; -webkit-text-stroke: 1.5px #6b6b6b; }
.estrella.llena { color: var(--dorado); -webkit-text-stroke: 1.5px var(--borde); }

.medallas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.medalla {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  border: 2px solid var(--borde);
  border-radius: 12px;
  background: #f1eee6;
  color: var(--texto-suave);
  font-size: 1rem;
  text-align: center;
}

.medalla.conseguida { background: var(--dorado); color: var(--texto); font-weight: 800; box-shadow: 3px 3px 0 var(--borde); }
.medalla-icono { font-size: 2rem; line-height: 1.2; }

.pie { text-align: center; margin-top: 8px; }
.pie a { display: inline-block; padding: 12px; font-weight: 700; }

/* ---------- Aviso de instalación ---------- */

.aviso-instalacion {
  background: var(--texto);
  color: #fff;
  border-radius: var(--radio);
  box-shadow: 4px 4px 0 var(--primario);
  padding: 20px;
  margin-bottom: 20px;
}

.pasos-instalacion {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  list-style: none;
  counter-reset: paso;
  margin: 0 0 12px;
  padding: 0;
}

.pasos-instalacion li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  color: var(--texto);
  border-radius: 12px;
  padding: 12px;
  counter-increment: paso;
}

.pasos-instalacion li::before {
  content: counter(paso);
  font-size: 1.6rem;
  font-weight: 800;
}

.icono-paso {
  flex: none;
  width: 48px;
  height: 48px;
  fill: none;
  stroke: var(--borde);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Cuestionario ---------- */

.titulo-actividad { font-size: 1.5rem; margin-bottom: 10px; }

.barra-progreso {
  height: 16px;
  overflow: hidden;
  background: #fff;
  border: var(--grosor) solid var(--borde);
  border-radius: 999px;
}

.barra-progreso span {
  display: block;
  height: 100%;
  background: var(--primario);
  transition: width 0.25s;
}

.contador { margin: 8px 0; font-weight: 700; }
.pregunta { font-size: 2rem; text-align: center; margin: 8px 0 20px; }

.opciones {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.opcion { min-height: 76px; font-size: 1.5rem; }
.opcion:disabled { color: var(--texto); opacity: 1; }
.opcion.correcta { background: var(--bien); }
.opcion.incorrecta { background: var(--mal); }

.zona-respuesta { text-align: center; margin-top: 16px; }
.zona-respuesta:empty { margin: 0; }
.mensaje-bien { color: var(--bien-borde); font-weight: 800; }
.mensaje-mal { color: var(--mal-borde); font-weight: 800; }

/* ---------- Mi resumen ---------- */

.fila-resumen {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 0;
  border-bottom: 2px solid #e3e5ee;
  font-size: 1.3rem;
}

.fila-resumen:last-child { border-bottom: 0; }
.fila-resumen small { display: block; color: var(--texto-suave); font-size: 1.05rem; }

.barra-tema { margin-bottom: 14px; font-size: 1.25rem; }

.barra-tema-titulo {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

.barra-tema-fondo {
  height: 18px;
  overflow: hidden;
  background: #f1eee6;
  border: 2px solid var(--borde);
  border-radius: 999px;
}

.barra-tema-fondo span {
  display: block;
  height: 100%;
  background: var(--primario);
}

/* ---------- Código de seguridad ---------- */

.caja-qr { max-width: min(420px, 100%); margin: 0 auto 16px; }
.caja-qr svg { display: block; width: 100%; height: auto; }

.texto-codigo {
  width: 100%;
  min-height: 110px;
  padding: 12px;
  border: var(--grosor) solid var(--borde);
  border-radius: 12px;
  background: #fff;
  color: var(--texto);
  font: 16px/1.3 ui-monospace, Menlo, monospace;
  word-break: break-all;
}

.visor-camara {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 12px;
  border-radius: 12px;
  background: #000;
}

.visor-camara[hidden] { display: none; }

.boton-archivo { position: relative; overflow: hidden; }

.boton-archivo input {
  position: absolute;
  inset: 0;
  opacity: 0;
  font-size: 0;
  cursor: pointer;
}

.mensaje-estado { min-height: 1.4em; margin-top: 12px; font-weight: 700; }

/* ---------- Avisos y ventanas ---------- */

.aviso-guardado {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--texto);
  color: #fff;
  font-size: 0.9rem;
  z-index: 5;
}

.dialogo {
  width: min(520px, calc(100% - 32px));
  border: var(--grosor) solid var(--borde);
  border-radius: var(--radio);
  box-shadow: 8px 8px 0 var(--borde);
  padding: 20px;
  color: var(--texto);
}

.dialogo::backdrop { background: rgb(47 44 58 / 0.6); }

/* ---------- Celebración ---------- */

.celebracion {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 16px;
  background: rgb(47 44 58 / 0.7);
}

.celebracion-tarjeta {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  padding: 24px;
  background: var(--tarjeta);
  border: var(--grosor) solid var(--borde);
  border-radius: var(--radio);
  box-shadow: 8px 8px 0 var(--borde);
  text-align: center;
  animation: aparecer 0.35s ease-out;
}

.celebracion .estrellas { font-size: 3.4rem; margin-bottom: 12px; }
.celebracion .boton { display: flex; width: 100%; margin-top: 12px; }
.celebracion-medalla { font-size: 1.3rem; font-weight: 800; margin: 4px 0; }

.confeti {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  animation: caer 2s ease-in forwards;
}

@keyframes aparecer {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes caer {
  to { transform: translateY(110vh) rotate(540deg); }
}

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

/* ---------- Horizontal y pantallas pequeñas ---------- */

@media (orientation: landscape) {
  .opciones { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 560px) {
  .opciones { grid-template-columns: repeat(2, 1fr); }
  main { padding: 16px; border-radius: 20px; }
  h1 { font-size: 1.8rem; }
}
