:root {
	--mf-navy: #14213d;
	--mf-blue: #2563eb;
	--mf-blue-dark: #1d4ed8;
	--mf-yellow: #fcd34d;
	--mf-yellow-dark: #e0b525;
	--mf-orange: #f97316;
	--mf-teal: #0f766e;
	--mf-red: #dc2626;
	--mf-bg: #f5f9ff;
	--mf-line: #dbe4f0;
	--mf-muted: #64748b;
	--mf-sol: #1d4ed8;
}

@font-face {
	font-family: "Nunito Fichas";
	src: url("fuentes/nunito-400.ttf") format("truetype");
	font-weight: 400;
	font-display: swap;
}
@font-face {
	font-family: "Nunito Fichas";
	src: url("fuentes/nunito-700.ttf") format("truetype");
	font-weight: 700;
	font-display: swap;
}
@font-face {
	font-family: "Nunito Fichas";
	src: url("fuentes/nunito-800.ttf") format("truetype");
	font-weight: 800;
	font-display: swap;
}
@font-face {
	font-family: "Nunito Fichas";
	src: url("fuentes/nunito-900.ttf") format("truetype");
	font-weight: 900;
	font-display: swap;
}

#generador-fichas { scroll-margin-top: 96px; }
.mf-app, .mf-app *, .mf-taller-pdf, .mf-taller-pdf * { box-sizing: border-box; }
.mf-app { color: var(--mf-navy); font: 400 16px/1.5 "Nunito Fichas", system-ui, sans-serif; }

/* Panel + vista previa */
.mf-app { display: grid; grid-template-columns: minmax(235px, 29%) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .mf-app { grid-template-columns: minmax(0, 1fr); } }
.mf-app > * { min-width: 0; }

.mf-panel {
	background: #fff;
	border: 1px solid var(--mf-line);
	border-radius: 18px;
	padding: 20px;
	position: sticky;
	top: 90px;
	box-shadow: 0 6px 20px rgba(20, 33, 61, .06);
}
@media (max-width: 900px) { .mf-panel { position: static; } }
#ficha-app .mf-panel h3 { font-size: 18px; margin: 0 0 14px; }
.mf-field { margin-bottom: 16px; border: 0; padding: 0; min-width: 0; }
.mf-field legend { font-weight: 800; font-size: 14px; margin-bottom: 6px; padding: 0; }
.mf-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.mf-seg input { position: absolute; opacity: 0; pointer-events: none; }
.mf-seg label {
	flex: 1 1 auto;
	text-align: center;
	border: 2px solid var(--mf-line);
	border-radius: 10px;
	padding: 7px 8px;
	font-weight: 800;
	font-size: 14px;
	cursor: pointer;
	white-space: nowrap;
	background: #fff;
}
.mf-seg input:checked + label { border-color: var(--mf-blue); background: #eef4ff; color: var(--mf-blue-dark); }
.mf-seg input:focus-visible + label { outline: 3px solid var(--mf-yellow); }
.mf-seg.mf-multi label { flex: 0 0 44px; padding: 7px 0; }
.mf-hint { font-size: 12px; color: var(--mf-muted); margin-top: 5px; line-height: 1.35; }
.mf-check { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.mf-check input { width: 18px; height: 18px; accent-color: var(--mf-blue); }
.mf-btn {
	display: block;
	width: 100%;
	border: 0;
	border-radius: 12px;
	padding: 13px 14px;
	font: inherit;
	font-weight: 900;
	font-size: 15px;
	cursor: pointer;
	margin-top: 10px;
	color: var(--mf-navy);
}
.mf-btn:active { transform: translateY(2px); }
.mf-btn-yellow { background: var(--mf-yellow); box-shadow: 0 4px 0 var(--mf-yellow-dark); }
.mf-btn-blue { background: var(--mf-blue); color: #fff; box-shadow: 0 4px 0 var(--mf-blue-dark); }
.mf-btn-teal { background: var(--mf-teal); color: #fff; box-shadow: 0 4px 0 #0b4f4a; }
.mf-btn-ghost { background: #fff; border: 2px solid var(--mf-line); }
.mf-btn:disabled { opacity: .7; cursor: wait; }
.mf-taller-pdf { position: absolute; left: -10000px; top: 0; width: 210mm; background: #fff; }
.mf-msg { font-size: 13px; color: var(--mf-teal); font-weight: 800; min-height: 18px; margin-top: 8px; text-align: center; }
.mf-enlace-manual {
	width: 100%;
	margin-top: 6px;
	border: 2px solid var(--mf-line);
	border-radius: 10px;
	padding: 8px;
	font: inherit;
	font-size: 16px;
	color: var(--mf-navy);
}

.mf-vista-label { font-weight: 800; font-size: 14px; color: #475569; margin: 0 0 10px; }
.mf-marco-hoja { margin: 0 auto 24px; position: relative; overflow: hidden; }
.mf-marco-hoja.mf-apagada { opacity: .4; }

/* Hoja A4 */
.mf-hoja {
	width: 210mm;
	height: 297mm;
	background: #fff;
	padding: 12mm 14mm 10mm;
	box-shadow: 0 10px 30px rgba(20, 33, 61, .12);
	display: flex;
	flex-direction: column;
	transform-origin: top left;
	overflow: hidden;
	font: 400 16px/1.5 "Nunito Fichas", system-ui, sans-serif;
	color: var(--mf-navy);
}
.mf-hoja-cab {
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 3px solid var(--mf-yellow);
	padding-bottom: 3mm;
	margin-bottom: 4mm;
}
.mf-marca { display: flex; align-items: center; gap: 2.5mm; }
.mf-marca .mf-logo { width: 14mm; height: 14mm; }
.mf-marca .mf-wordmark { height: 8mm; width: auto; }
.mf-hoja img.mf-logo, .mf-hoja img.mf-wordmark, #ficha-app .mf-hoja img { margin: 0; border-radius: 0; }
#ficha-app .mf-marca .mf-wordmark { height: 8mm; }
#ficha-app .mf-marca .mf-logo { height: 14mm; }
.mf-curso { background: var(--mf-yellow); border-radius: 999px; padding: 4px 12px; font-weight: 900; font-size: 13px; }
.mf-badge-sol { background: #fee2e2; color: var(--mf-red); border-radius: 999px; padding: 4px 12px; font-weight: 900; font-size: 13px; }
.mf-hoja .mf-hoja-titulo, #ficha-app .mf-hoja-titulo { font-size: 24px; font-weight: 900; line-height: 1.18; margin: 0 0 1.5mm; color: var(--mf-navy); }
.mf-hoja-instr { font-size: 14px; margin: 0 0 4mm; line-height: 1.4; }
.mf-alumno { display: flex; gap: 8mm; font-weight: 800; font-size: 14px; margin-bottom: 5mm; }
.mf-alumno div { flex: 1; display: flex; align-items: flex-end; gap: 6px; }
.mf-alumno div.mf-corto { flex: 0 0 45mm; }
.mf-alumno .mf-raya { flex: 1; border-bottom: 1.5px solid #94a3b8; height: 18px; }

.mf-rejilla { display: grid; align-content: start; gap: var(--mf-gap-y, 6mm) var(--mf-gap-x, 4mm); }
.mf-item { position: relative; display: flex; justify-content: center; align-items: center; }
.mf-item.mf-con-marco { border: 1.5px solid var(--mf-line); border-radius: 10px; padding: 4mm 2mm 3mm; }
.mf-item.mf-en-linea { justify-content: flex-start; border-bottom: 1px dashed var(--mf-line); padding: 0 0 1.5mm 8mm; min-height: var(--mf-fila, 11mm); }
.mf-num { position: absolute; top: 1.5mm; left: 2.5mm; font-size: 11px; font-weight: 900; color: #94a3b8; }
.mf-en-linea .mf-num { top: auto; bottom: 2.5mm; left: 0; }

.mf-hoja-pie {
	margin-top: auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-top: 3mm;
	border-top: 1px solid var(--mf-line);
	font-size: 12px;
	color: var(--mf-muted);
	font-weight: 700;
}
.mf-web { display: flex; align-items: center; gap: 2mm; color: var(--mf-navy); font-weight: 900; font-size: 15px; }
.mf-web .mf-logo { width: 7mm; height: 7mm; }
.mf-estrellas { display: flex; gap: 2.5mm; align-items: center; font-weight: 800; color: var(--mf-navy); }
.mf-estrellas i {
	width: 6.5mm;
	height: 6.5mm;
	display: inline-block;
	clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
	background: #e2e8f0;
}

/* Piezas de las fichas */
.mf-tam-xs { --mf-celda: 6mm; --mf-alto: 7.5mm; --mf-letra: 17px; }
.mf-tam-xs .mf-linea { gap: 1.6mm; }
.mf-tam-s { --mf-celda: 6.5mm; --mf-alto: 8mm; --mf-letra: 20px; }
.mf-tam-m { --mf-celda: 8mm; --mf-alto: 9mm; --mf-letra: 25px; }
.mf-tam-l { --mf-celda: 10mm; --mf-alto: 10.5mm; --mf-letra: 30px; }

.mf-vertical {
	display: grid;
	grid-template-columns: repeat(var(--mf-cols), var(--mf-celda));
	font-size: var(--mf-letra);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	line-height: 1;
}
.mf-vertical > span { height: var(--mf-alto); display: flex; align-items: center; justify-content: center; }
.mf-vertical > span.mf-fila-llevada { height: calc(var(--mf-alto) * .72); }
.mf-vertical > span.mf-regla { grid-column: 1 / -1; height: 0; border-top: 2.5px solid var(--mf-navy); margin: 1mm 0 1.5mm; }
.mf-llevada {
	width: calc(var(--mf-celda) * .7);
	height: calc(var(--mf-celda) * .7);
	border: 1.5px dashed #94a3b8;
	border-radius: 3px;
	font-size: calc(var(--mf-letra) * .55);
	color: var(--mf-red);
	font-weight: 900;
	display: flex;
	align-items: center;
	justify-content: center;
}
.mf-llevada.mf-sin-borde { border-color: transparent; }

.mf-caja {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: calc(var(--mf-celda, 8mm) * .95);
	height: calc(var(--mf-alto, 9mm) * .95);
	border: 1.5px solid #cbd5e1;
	border-radius: 4px;
	color: var(--mf-sol);
	font-weight: 900;
	padding: 0 1mm;
}
.mf-vertical .mf-caja { width: calc(var(--mf-celda) * .92); min-width: 0; padding: 0; }
.mf-soluciones .mf-vertical .mf-caja { border-color: transparent; }
.mf-caja.mf-ancha { min-width: 16mm; }
.mf-circulo {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: calc(var(--mf-alto, 9mm) * .95);
	height: calc(var(--mf-alto, 9mm) * .95);
	border: 1.5px solid #94a3b8;
	border-radius: 50%;
	color: var(--mf-sol);
	font-weight: 900;
}

.mf-linea {
	display: flex;
	align-items: center;
	gap: 2.2mm;
	font-size: var(--mf-letra);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	flex-wrap: wrap;
}
.mf-centro { min-width: 12mm; text-align: center; }
.mf-pasos { font-size: 13px; font-weight: 700; color: var(--mf-sol); margin-top: 1.5mm; line-height: 1.5; }
.mf-pasos span { display: inline-block; white-space: nowrap; margin-right: 3mm; }
.mf-bloque { display: flex; flex-direction: column; align-items: flex-start; width: 100%; }
.mf-renglones { width: 100%; margin-top: 2mm; }
.mf-renglones i { display: block; height: 7mm; border-bottom: 1px solid #e2e8f0; }

/* División (formato español) */
.mf-division {
	display: grid;
	grid-template-columns: auto auto;
	font-size: var(--mf-letra);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	letter-spacing: .12em;
	line-height: 1;
	width: 100%;
	justify-content: center;
}
.mf-div-dividendo { padding: 1.5mm 3mm 1.5mm 0; text-align: right; }
.mf-div-divisor { border-left: 2.5px solid var(--mf-navy); border-bottom: 2.5px solid var(--mf-navy); padding: 1.5mm 2mm 1.5mm 3mm; min-width: 18mm; }
.mf-div-trabajo { min-height: var(--mf-trabajo, 18mm); }
.mf-div-cociente { padding: 2mm 0 0 3mm; color: var(--mf-sol); font-weight: 900; }
.mf-div-resto { grid-column: 1 / -1; font-size: 14px; letter-spacing: 0; font-weight: 800; display: flex; align-items: center; gap: 2mm; margin-top: 1mm; }
.mf-div-resto .mf-caja { --mf-alto: 8mm; --mf-celda: 9mm; font-size: 18px; }
.mf-prueba { grid-column: 1 / -1; font-size: 12px; letter-spacing: 0; color: var(--mf-sol); font-weight: 700; margin-top: 1.5mm; }

@page { size: A4; margin: 0; }
@media print {
	body.matecitos-worksheet-ready,
	body.matecitos-worksheet-ready :has(#ficha-app) {
		margin: 0 !important;
		padding: 0 !important;
		width: auto !important;
		max-width: none !important;
		background: #fff;
		border: 0 !important;
		box-shadow: none !important;
		overflow: visible !important;
	}
	body.matecitos-worksheet-ready :not(:has(#ficha-app), #ficha-app, #ficha-app *) { display: none !important; }
	#ficha-app .mf-panel, #ficha-app .mf-vista-label { display: none !important; }
	.mf-app { display: block; }
	.mf-marco-hoja { width: auto !important; height: auto !important; margin: 0 !important; opacity: 1 !important; overflow: visible; }
	.mf-marco-hoja.mf-no-imprimir { display: none !important; }
	.mf-hoja { transform: none !important; box-shadow: none; break-after: page; page-break-after: always; }
	.mf-marco-hoja.mf-ultima .mf-hoja { break-after: auto; page-break-after: auto; }
	#ficha-app * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
